Skip to content
Source
Sign inSign up
TanStack/router

Undefined context after redirect with wrapInSuspense at root route (introduced in 1.33.6) #1650

Send to my agent
ClosedZebeqo(GitHub profile, opens in a new tab) opened this issue 6 comments

Describe 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

  1. See the log: context: undefined
  2. Remove wrapInSuspense: true and refresh
  3. 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

  1. can you please check which version introduced this? 1.33.5 most likely did not since it affected @tanstack/start and not the router.

  2. 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

  3. Zebeqo(GitHub profile, opens in a new tab) changed the title

  4. 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.

  5. 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 wrapInSuspense which 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 🤔

  6. Yeah, restoring context assignment before beforeLoad reopens https://github.com/TanStack/router/issues/1637 as the replaceEqualDeep loses all dynamic values: then when beforeLoad runs, 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 updateMatch updating 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)

  7. SeanCassiere added labelsbug

  8. SeanCassiere closed this

Sign in to join this conversation.