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

Context providers passed to Route element attribute are broken #13118

Open
madisp opened this issue Feb 25, 2025 · 2 comments
Open

Context providers passed to Route element attribute are broken #13118

madisp opened this issue Feb 25, 2025 · 2 comments
Labels

Comments

@madisp
Copy link

madisp commented Feb 25, 2025

I'm using React Router as a...

library

Reproduction

using <...Context.Provider> tags within the <Route element=... /> attr seems to be broken.

Issue can be worked around with:

  • by downgrading to react-router 7.1.3 or older
  • by moving the <Context.Provider> tags outside of the react router (not always feasible as you may have route-specific contexts)
  • by moving <Context.Provider> tags into a separate react component that gets used in the element attr. (The /alt route in the reproducing project).

System Info

node 22.14.0
react-router 7.1.4
vite 6.2.0
typescript 5.7.3
chrome 133.0.6943.127

Used Package Manager

npm

Expected Behavior

Using react context providers within <Route /> elements work, example from the reproducing code:

<Route path="/" element={
  <CounterContext.Provider value={counter}>
    <Count />
    <Increment />
  </CounterContext.Provider>
} />

expected result: count increases (react-router 7.1.3 or older)

Actual Behavior

actual result: count does not increase (react router 7.1.4 or newer)

@madisp madisp added the bug label Feb 25, 2025
@madisp
Copy link
Author

madisp commented Feb 25, 2025

NOTE: I'm not really a js/ts/frontend dev but encountered the bug. It might be I've just been using react-router wrong or in a weird way but seeing context providers break in a patch version was a bit surprising.

@meyerjoe
Copy link

meyerjoe commented Feb 26, 2025

+1

Just ran into the same issue with a context provider in a more complex setup. Haven't properly isolated it yet.
Seems like a state change in the provider value doesn't trigger a rendering of the route element anymore in my setup.
Worked until 7.1.3 , but not anymore since 7.1.4

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

No branches or pull requests

2 participants