Skip to content

useContext does not work when ContextProvider is declared in route after HMR #10113

Open
@pstachula-dev

Description

@pstachula-dev

Reproduction

  1. Go to the route /test.
  2. Click on click
  3. Check the developer console - it should work correctly - both inside + outside change state
  4. Change the code, add a space or something.... now after HMR inside is fine, but outside has the wrong state

When I move the BugContext from the route to a separate file, it starts working correctly.

https://stackblitz.com/edit/remix-run-remix-v7duwb?file=app%2Froutes%2Ftest.tsx

System Info

System:
    OS: Linux 6.11 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 24.47 GB / 31.27 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 9.9.0 - ~/.nvm/versions/node/v20.17.0/bin/pnpm
    bun: 1.1.27 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 129.1.70.123
    Chromium: 129.0.6668.89
  npmPackages:
    @remix-run/dev: ^2.13.1 => 2.13.1
    @remix-run/node: ^2.13.1 => 2.13.1
    @remix-run/react: ^2.13.1 => 2.13.1
    @remix-run/serve: ^2.13.1 => 2.13.1
    vite: ^5.1.0 => 5.4.3

Used Package Manager

npm

Expected Behavior

Context should works in children component

Actual Behavior

Context work only for children declareated inside route

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions