Skip to content

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

Closed
@ImSingee

Description

@ImSingee

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions