Skip to content

Context wrapper breaking HMR #464

@joakimbo

Description

@joakimbo

Related plugins

Describe the bug

Hi, being new to Vite, React and Typescript this might be a "me issue" but I have stumbled onto something when wanting to use a simple wrapper for contexts (generalising use<context> functions). But simply defining this wrapper causes a throw to be made of not using the context inside of its provider.

A similar but long ago closed issue is vitejs/vite#3301 but it might be a red herring since I'm not totally sure where the origin of the my issue lies.

Reproduction

https://github.com/joakimbo/vite_react_hmr

Steps to reproduce

  1. npm install
  2. npm run dev
  3. modify count-provider.tsx, save and you should see Uncaught Error: countContext has to be used within <CountContext.Provider> in the console

System Info

Edit: not sure why it wasn't included but I have been using Firefox 137.0.2 (64-bit)

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 42.69 GB / 63.10 GB
  Binaries:
    Node: 22.14.0 - ~\AppData\Local\fnm_multishells\125216_1745080843483\node.EXE
    npm: 10.9.2 - ~\AppData\Local\fnm_multishells\125216_1745080843483\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    @vitejs/plugin-react-swc: ^3.8.0 => 3.9.0
    vite: ^6.3.1 => 6.3.2

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions