Skip to content

Pages rendered through <Outlet /> don't re-render when a consumed react context changes value, with ssr: false #13834

@lscheibel

Description

@lscheibel

I'm using React Router as a...

library

Reproduction

https://stackblitz.com/edit/github-sgy5asnz?file=app%2Froutes%2Flayout.tsx

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @react-router/dev: 7.6.2 => 7.6.2 
    @react-router/node: 7.6.2 => 7.6.2 
    @react-router/serve: 7.6.2 => 7.6.2 
    react-router: 7.6.2 => 7.6.2 
    vite: ^6.3.3 => 6.3.5

Used Package Manager

npm

Expected Behavior

React components using react context should re-render when the context value changes, even when the context provider is part of a layout page and the consumer is rendered through an <Outlet />.

Actual Behavior

When the react-router config has ssr: false, components that are rendered through an <Outlet /> will not re-render when a consumed react context (e.g.: React.useContext(MyContext)) changes its value, leading to stale state. Note that sometimes after HMR it behaves correctly, however as soon as the page is reloaded (using the browser's reload button) the bug appear again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions