TanStack / TanStack/router

beforeLoad return type circular reference error regression somewhere between versions 1.130.12 and 1.134.13

Open
#5,786 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

types
Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Router

Describe the bug

This piece of code

export const Route = createFileRoute('/_authenticated')({
  beforeLoad: ({ context }) => {
    return {
      crumbs: [
        ...context.crumbs,
        {
          text: 'Some Text',
          // ❌ This line breaks type inference
          to: Route.fullPath,
        },
      ],
    };
  },
  component: RouteComponent,
});

works ok in 1.130.12 without any TS errors

Image
Your Example Website or App

https://stackblitz.com/edit/github-vblwkxuv?file=src%2Froutes%2F_authenticated%2Froute.tsx

Steps to Reproduce the Bug or Issue

Use the code example above in versions beyond 1.130.12. The fact that we are using the Route reference inside beforeLoad causes the type error. (there is no actual runtime error, since this is valid object reference inside the function body, similar to

function createObj(x: string) {
  return function <T>(x: T) {
    return x
  }
}

const test = createObj('')({
  a: 1,
  func: () => {
    return test.a
  },
})

)

Expected behavior

For the above code to work with no type errors

Screenshots or Videos
Image Image Image
Platform
  • Router: 1.134.13
  • OS: Linux
  • Browser: Chrome
  • Browser Version: 142.0.7444.134
  • Bundler: vite
  • Bundler Version: 7.2.2
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in src/routes/_authenticated/route.tsx from the linked StackBlitz project and compare its type-checking behavior between versions 1.130.12 and 1.134.13. Confirm the circular reference error around Route.fullPath inside beforeLoad, then verify that the example works without TypeScript errors in the affected version range.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript, vite
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.