You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getRouteApi().useRouteContext() returns undefined for beforeLoad context values in v1.140.1+ #6082
The app was working fine till version 1.40.0 , below commands can verify
start the backend bun --filter bun_api_space dev
run the e2e testcases, cd to tanstack_router_space project, then run bun run test:e2e
After I have upgraded to 1.40.1, the e2e test command started failing
Also when I run the app in dev mode, its not working, it seems authClient is not defined
changed the title [-]My app starts breaking after I upgrade to version 1.40.1 from 1.40.0, most probably due to beforeLoad changes[/-][+]My app starts breaking after I upgrade to version 1.40.1 from 1.40.0[/+]on Dec 12, 2025
Yes, I have tried with latest version as well, getting the same issue.
I get the following error when I am running in dev mode
TypeError: Cannot read properties of undefined (reading 'useSession')
at SignedOut (auth-components.tsx:22:49)
at Object.react_stack_bottom_frame (react-dom_client.js?v=cc2383de:18509:20)
at renderWithHooks (react-dom_client.js?v=cc2383de:5654:24)
at updateFunctionComponent (react-dom_client.js?v=cc2383de:7475:21)
at beginWork (react-dom_client.js?v=cc2383de:8525:20)
at runWithFiberInDEV (react-dom_client.js?v=cc2383de:997:72)
at performUnitOfWork (react-dom_client.js?v=cc2383de:12561:98)
at workLoopSync (react-dom_client.js?v=cc2383de:12424:43)
at renderRootSync (react-dom_client.js?v=cc2383de:12408:13)
at performWorkOnRoot (react-dom_client.js?v=cc2383de:11827:37)
actually on or before 1.40.0 version, Signout component was not being executed I believe, only after the beforeLoad of __root executes completely then other components start executing. it seems that has changed somehow now.
after you update the version back to 1.40.0, the error goes away.
Kindly see below images with console logs, there is a difference in the sequence of logs:
version 1.40.0
version 1.40.1
in the above images, we see after we upgrade to the faulty version, the logs changes a bit towards the end.
during my debugging, in the new falty version, the authClient is defined during the beforeLoad execution after authClient is awaited. but its not available in SignedOut component when we access it using useAuthClient() hook
I tried to dig through the router code using cursor, and found this info below, hope this would be useful for you guys
Title: getRouteApi().useRouteContext() returns undefined for beforeLoad context values in v1.140.1+
The change in PR #6053 ("commit route context") defers context updates until after the loader completes.
For routes without a loader, useRouteContext() returns undefined for values returned from beforeLoad.
Regression in: v1.140.1
Working in: v1.140.0
Root cause: packages/router-core/src/load-matches.ts now only calls commitContext()
after the loader, but useRouteContext() reads match.context which is not updated
after beforeLoad alone.
changed the title [-]My app starts breaking after I upgrade to version 1.40.1 from 1.40.0[/-][+]getRouteApi().useRouteContext() returns undefined for beforeLoad context values in v1.140.1+[/+]on Dec 16, 2025
Also ran into this issue - I hope it's not an intentional change. @amanmavai can you explain how exactly adding a loader should avoid the issue? Would that be a loader on the route that is adding to context, or in the child route that consumes that context?
and when using it like this inside my RouteComponent i get this locallyCannot read properties of undefined (reading 'queryFn'). After refreshing it's ok, until i hard refresh and go to this route again. Happens only locally for me, in production is working.
I actually am seeing this issue in production. It's rare, but I got a sentry alert from it yesterday. So I don't think it's a dev-only issue, though it is much more common in dev.
I actually am seeing this issue in production. It's rare, but I got a sentry alert from it yesterday. So I don't think it's a dev-only issue, though it is much more common in dev.
I cannot understand why and when it triggers or if there is a workaround to fix it. I keep trying to reproduce it on production but no way… in dev it's constantly happening.
For my case, the issue appeared exactly after 1.140.1 and it's not fixed after #6407 (1.151.2) 🥹
Could you take a look at the issue if something else is wrong?
For my case, my router looks like this
pathless layout + beforeLoad
page A + loader
page B
When I navigate from page A to page B, the beforeLoad from layout context is initlally empty.
layout beforeLoad start
layout beforeLoad end
page A loader start
page A render beforeLoad: false loader: true
page A render beforeLoad: false loader: true
page A loader end
page A render beforeLoad: true loader: true
page A render beforeLoad: true loader: true
here is the log, the beforeLoad is fired but it is not injected to useRouteContext call inside page A. Then after the page loader invalidates it rerenders the page - and the beforeLoad is correctly filled.
I am willing to create a reproduction but the behavior is very inconsistent :(
Activity
coderabbitai commentedon Dec 12, 2025
📝 CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
Examples
🔗 Related PRs
#5406 - fix(router-devtools-core): bundle solid for smaller package [merged]
#5422 - fix(router-devtools-core): actually bundle solid [merged]
#5474 - chore: bump @tanstack/config to v0.22.0 [merged]
#5680 - fix(router): bump tanstack store to ^0.8 [merged]
👤 Suggested Assignees
🧪 Issue enrichment is currently in early access.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:[-]My app starts breaking after I upgrade to version 1.40.1 from 1.40.0, most probably due to beforeLoad changes[/-][+]My app starts breaking after I upgrade to version 1.40.1 from 1.40.0[/+]schiller-manuel commentedon Dec 12, 2025
please try latest version, and if that doesn't work either, please provide error messages.
amanmavai commentedon Dec 12, 2025
Yes, I have tried with latest version as well, getting the same issue.
I get the following error when I am running in dev mode
actually on or before 1.40.0 version, Signout component was not being executed I believe, only after the beforeLoad of __root executes completely then other components start executing. it seems that has changed somehow now.
schiller-manuel commentedon Dec 12, 2025
would be great if you could strip down the reproducer to the bare minimum
amanmavai commentedon Dec 13, 2025
I have created another tanstack router repo which is CSR app, with this app, we are able to reproduce the issue without the backend.
https://github.com/amanmavai/tanstack_router_open/tree/main
use following commands
after you update the version back to 1.40.0, the error goes away.
Kindly see below images with console logs, there is a difference in the sequence of logs:
version 1.40.0
version 1.40.1
in the above images, we see after we upgrade to the faulty version, the logs changes a bit towards the end.
during my debugging, in the new falty version, the authClient is defined during the beforeLoad execution after authClient is awaited. but its not available in SignedOut component when we access it using
useAuthClient()hookamanmavai commentedon Dec 14, 2025
It seems this might be because of the way I access root route context in this code
is this way not supported anymore? esp on or after 1.40.1. if so what is the correct way to access root route context in a common hook
amanmavai commentedon Dec 14, 2025
I tried to dig through the router code using cursor, and found this info below, hope this would be useful for you guys
[-]My app starts breaking after I upgrade to version 1.40.1 from 1.40.0[/-][+]getRouteApi().useRouteContext() returns undefined for beforeLoad context values in v1.140.1+[/+]amanmavai commentedon Dec 17, 2025
@schiller-manuel could you check this now, I have provided the relevant information as requested
dylanhu7 commentedon Dec 19, 2025
Also ran into this issue - I hope it's not an intentional change. @amanmavai can you explain how exactly adding a
loadershould avoid the issue? Would that be aloaderon the route that is adding tocontext, or in the child route that consumes that context?schiller-manuel commentedon Dec 19, 2025
@dylanhu7 no this not an intentional change, it's a bug
amanmavai commentedon Jan 10, 2026
@schiller-manuel , any update on this issue, This is a blocker for my usecase, I have not been able to upgrade my app since this issue
TommysG commentedon Jan 15, 2026
Same problem here. I have this in my file route:
and when using it like this inside my RouteComponent i get this locally
Cannot read properties of undefined (reading 'queryFn'). After refreshing it's ok, until i hard refresh and go to this route again. Happens only locally for me, in production is working.willhoney7 commentedon Jan 16, 2026
I actually am seeing this issue in production. It's rare, but I got a sentry alert from it yesterday. So I don't think it's a dev-only issue, though it is much more common in dev.
TommysG commentedon Jan 16, 2026
I cannot understand why and when it triggers or if there is a workaround to fix it. I keep trying to reproduce it on production but no way… in dev it's constantly happening.
fix: Commit context together with status to avoid race condition
ha1fstack commentedon Feb 3, 2026
Hi @schiller-manuel
For my case, the issue appeared exactly after 1.140.1 and it's not fixed after #6407 (1.151.2) 🥹
Could you take a look at the issue if something else is wrong?
For my case, my router looks like this
When I navigate from page A to page B, the beforeLoad from layout context is initlally empty.
here is the log, the beforeLoad is fired but it is not injected to useRouteContext call inside page A. Then after the page loader invalidates it rerenders the page - and the beforeLoad is correctly filled.
I am willing to create a reproduction but the behavior is very inconsistent :(
schiller-manuel commentedon Feb 3, 2026
@ha1fstack please open a new issue including a complete reproducer project