Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes the child route doesn't inherit parent context #3430

Open
ImSingee opened this issue Feb 14, 2025 · 1 comment
Open

Sometimes the child route doesn't inherit parent context #3430

ImSingee opened this issue Feb 14, 2025 · 1 comment

Comments

@ImSingee
Copy link

Which project does this relate to?

Router

Describe the bug

I recently encountered an issue where the parent route sets a context value in beforeLoad, but the child route does not inherit it.

I've posted this in #3403 (reply in thread) previously.

Your Example Website or App

https://stackblitz.com/~/github.com/ImSingee/tanstack-router-bug-report-hauecq3w

Steps to Reproduce the Bug or Issue

  1. Go to /, and the browser will redirect you to /login at the first time
  2. Click "Login", and the browser will set some state and redirect you to the /feed/all page
  3. In the /feed/all page, it shows feedId = (error)
  4. See the router devtools, the context feedId exists in /feed/all but not /feed/all/
  5. Refresh the page, it shows feedId = "all" (expected)

(If you need, you can click the logout button and restart from the step 1 to see or inspect the situation again)

Expected behavior

In the step 3, it should show feedId = "all". In the step 4, the context in the /feed/all/ should be the same as /feed/all

Screenshots or Videos

Image Image

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 132.0.2957.140 (Official build) (arm64)

Additional context

I try my best to make the reproduce example minimal. But the trigger condition is indeed complex.

Most interesting, if change the last line of SyncProvider (/src/lib/sync/provider.tsx) from return <AContext.Provider value={db}>{children}</AContext.Provider>; to return children, the issue disappears.

@schiller-manuel
Copy link
Contributor

thanks for the good reproducer.
i noticed that if you convert the loader in src/routes/login/callback.tsx to a beforeLoad, it also works.
So there must be some race condition / timing issue that appears when a redirect is thrown from a loader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants