Undefined context after redirect with wrapInSuspense at root route (introduced in 1.33.6) #1650
Send to my agentDescribe the bug#
Undefined context after redirect with wrapInSuspense at root route.
It used to work fine in version 1.33.4.
Your Example Website or App#
https://stackblitz.com/edit/github-jr3nax-t75gmj?file=src%2Froutes%2F__root.tsx
Steps to Reproduce the Bug or Issue#
- See the log:
context: undefined - Remove
wrapInSuspense: trueand refresh - See the log:
context: {"test":"abc"}
Expected behavior#
See the log: context: {"test":"abc"} at step 1
Screenshots or Videos#
No response
Platform#
- OS: macOS
- Browser: Chrome
- Version: 125.0
Additional context#
No response
can you please check which version introduced this? 1.33.5 most likely did not since it affected @tanstack/start and not the router.
It's likely that the issue was introduced in version 1.33.6. I can confirm that version 1.33.4 was working fine, and version 1.33.6 has the issue. As for version 1.33.5, it doesn't appear to be available on npm.
1.33.4: https://stackblitz.com/edit/github-jr3nax-xxb2ka?file=package.json 1.33.6: https://stackblitz.com/edit/github-jr3nax-uphkrn?file=package.json
Zebeqo(GitHub profile, opens in a new tab) changed the title
I am also facing a similar issue. Everything works fine in version 1.33.4, but in 1.33.6, the loader's context becomes undefined. I haven't specified wrapInSuspense, but it seems to be the same problem.
then it is caused by this PR
https://github.com/TanStack/router/pull/1611
@SeanCassiere @freshgiammi
Yeah, looks like this is working when my change is reverted, but I'm not sure reverting the change is the right fix. My patch merely fixes support for
wrapInSuspensewhich got lost when some SSR changes were brought in (where the root route got forced to not suspend), so maybe this was broken before too. Seems we just keep bumping into ctx issues.Reverting this change restores context after the redirect https://github.com/TanStack/router/commit/e19f7e8703bdc8d6ccbaf3399c82527aabdc56c2#diff-2ac234f610fa0e0c2146252c10a5266af9c5b6d0b63659a0fa4c9f2c4472596a
I wonder if the root cause lays elsewhere 🤔
Yeah, restoring context assignment before
beforeLoadreopens https://github.com/TanStack/router/issues/1637 as thereplaceEqualDeeploses all dynamic values: then whenbeforeLoadruns, the already mounted layout component re-renders before the router has a chance to update the route context.I think what's happening here is
updateMatchupdating the store too early, causing a rerender with possibly invalid data being fed to already mounted components. I have opened https://github.com/TanStack/router/pull/1662 as a potential fix 👍 (and I'm thinking we need tests around redirects+context to try and detect these kind of issues early on)SeanCassiere added labelsbug
SeanCassiere closed this
Sign in to join this conversation.
can you please check which version introduced this? 1.33.5 most likely did not since it affected @tanstack/start and not the router.