beforeLoad return type circular reference error regression somewhere between versions 1.130.12 and 1.134.13 #5786
Send to my agentWhich 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
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#
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
schiller-manuel(GitHub profile, opens in a new tab) added labelstypes
eventually yes. not a high priority right now
I just want to give some extra feedback on this, in case it affects the priority:
It's not just the errors about self reference; it affects stuff such as search params to links or navigations as well. For example, see how many linter errors are produced in the RouteComponent because of the initial self-reference error. Practically every search param shows up as "any" (hence the linter errors)
linter errors when we reference the Route in the beforeload
vs linter errors without that initial error
Opened this: https://github.com/TanStack/router/pull/6936It's AI generated, with steering on my part. Seems to resolve the issue locally, so please let me know if it's up to par implementation wise toodisregard for now, sorry
Sign in to join this conversation.
@schiller-manuel any plans for this regression? Thanks