HMR breaks when modifying React context provider
See original GitHub issueDescribe the bug
Vite HMR breaks when modifying React context provider Related: https://github.com/vitejs/vite-plugin-react/issues/24
Reproduction
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 413.26 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.7.6 - ~/.nvm/versions/node/v15.14.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Brave Browser: 89.1.21.76
Chrome: 90.0.4430.93
Firefox: 87.0
Firefox Developer Edition: 89.0
Safari: 14.0.3
npmPackages:
vite: ^2.2.3 => 2.2.4
Used package manager: npm
Logs
Before submitting the issue, please make sure you do the following
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Provide a description in this issue that describes the bug.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:57
- Comments:51 (6 by maintainers)
Top Results From Across the Web
React Context HMR still has problem. Due to ... - Hacker News
React falters because there are not many community contributing towards react integration.
Read more >Hot Reloading in React. or, an Ode to Accidental Complexity
Before React Hot Loader, my first thought was that I could use Webpack HMR to replace the root component of my app and...
Read more >React Context State Update - Stack Overflow
You are not passing setUser to the StoreProvider value which means that you can't destructure it, and can't update your state. Later you...
Read more >Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
Context : React context providers live here. ... This can be fixed by extending the css-loader config and changing mode: 'local' property.
Read more >HMR API - Vite
This is the client HMR API. For handling HMR update in plugins, see handleHotUpdate. The manual HMR API is primarily intended for framework...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue here, but im trying to be more specific with that.
In my experience:
Running
npm run dev
works. Forcing a hot reload on this file, crashes (context gets default value for alluseContext
calls).Running
npm run dev
works. Forcing a hot reload on any of those files, still works.Tell me if you need more info, or a minium reproduction repo.
Hope it helps!
I’ve pushed up a PR that fixes this issue, according to a test I wrote based off the reproduction in the issue description. But, it requires a change to how Vite handles
import.meta.hot.invalidate()
, so I think it will need some discussion with the Vite team.