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

Router context not injected in child routes upon hydration #3278

Open
nedpals opened this issue Jan 30, 2025 · 0 comments
Open

Router context not injected in child routes upon hydration #3278

nedpals opened this issue Jan 30, 2025 · 0 comments

Comments

@nedpals
Copy link

nedpals commented Jan 30, 2025

Which project does this relate to?

Router

Describe the bug

I have a routing structure that involves creating nested layout routes like this:

routes/
  _auth/
    // ...page for authenticated
    some-auth-page.tsx
    _with_header/
      // ...page for authenticated + (with navbar)
      profile.tsx
  _guest/
    // ... page for guests
  _root.tsx
  some-page.tsx

The /_auth route is where it injects the current user data which can be accessed by all of the routes under it and for some routes that I need to add a header/navbar, I just put them inside the /_with_header group route. Again, /_with_header is a child route under the /_auth group route.

There were no problems so far up to the type completions. However when I go to /profile on a fresh load, the route context was not injected in the /_with_header layout upon hydration.

The problem disappears when beforeLoad is executed on client when navigating from another page.

Your Example Website or App

https://stackblitz.com/edit/github-9rncraue?file=app%2Froutes%2F_privileged%2F_another_one.tsx

Steps to Reproduce the Bug or Issue

  1. Create a parent _ group route and child _ group route under it. Create the layout routes for the said group routes.
  2. For the parent group route, inject any kind of payload into beforeLoad lifecycle.
  3. Add a page under the child group route and display the recently injected context data.
  4. In the browser, go to the said page, and expect that the data will be displayed for a brief moment and disappears upon hydration.

Expected behavior

The route context is injected as per docs.

Screenshots or Videos

Image

Here's from Devtools:

Image

And here's the details for the /_auth route:

Image

Similarly, as I make the reproduction, the /some-auth-page route I made under the /_auth route did not also get the context but only the layout.

Image

However, when I navigate to the profile page from the home page. The context is loaded as usual (beforeLoad is triggered on client):
Image

Platform

  • OS: macOS 14.6.1 Sonoma
  • Browser: Chrome
  • Version: 131 / TanStack Start 1.98.3

Additional context

I am also using Tanstack Query with the @tanstack/react-router-with-query package thus the queryClient is automatically injected into the route context. However, I also tried without and the issue still persists.

@nedpals nedpals changed the title Router context not injected on client on fresh load Router context not injected in child routes upon hydration Jan 30, 2025
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

1 participant