nuxt: HMR does not pick up updates to data
Environment
Running on WSL but have had the same issue in a containerized application…
Tested in latest Firefox and Chrome with identical results.
Nuxt CLI v3.0.0-27288761.d3fb512
RootDir: …
Nuxt project info:
- Operating System:
Linux - Node Version:
v16.13.0 - Nuxt Version:
3.0.0-27288761.d3fb512 - Package Manager:
yarn@1.22.17 - Bundler:
Vite - User Config:
- - Runtime Modules:
- - Build Modules:
-
Reproduction
https://github.com/radusuciu/nuxt3-app

Describe the bug
Updated data is not picked up by HMR. Updating the template is. Data updates are reflected after a full refresh only.
Potentially related to nuxt/nuxt.js#11956 but I don’t see any errors and it isn’t sporadic - it just doesn’t work even though Vite does seem to pick up the updates judging by the “Vite server built in XXms” logs messages and “[vite] hot updated: /app.vue” output in the console.
Additional context
I have no issues with HMR in nuxt2, nor if I use vite by itself.
Logs
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (9 by maintainers)
Thanks for sharing reproductions. I can confirm the same issue on WSL2 and also normal Linux servers and windows. HMR only works fine on a macOS laptop with fsevents.
An interesting finding is that native watcher, works but only for one instance. Disabling server [watcher] with
ssr: false, client watcher and HMR start to work.Ok, @danielroe, your instinct was right after all:
I kept digging inside @vitejs/plugin-vue and found out that if I add a 100ms sleep inside
handleHotUpdatefunction after file is read, the autoupdates start working. Then I’ve found this issue, and although it mentions Windows (this was also your instinct I guess, since you asked if I have Windows), the fix worked for me in Ubuntu:After I set
usePollingtotrue, it started working as expected. Thank you for your help, I guess this can be closed after @radusuciu confirms.I just verified that this is fixed with the latest version of nuxt! Thank you!
I have the same issue - using
npx nuxi init pure-nuxt3to create a fresh nuxt 3 project and then changingapp.vuetoBehavior is the same as described by @radusuciu - updating template works immediately, but whenever I change
countervalue, it’s not updated, only after full page refresh. Pureviteproject (created vianpm init vite-app pure-vite) doesn’t have this issue, bothtemplateandscriptchanges are picked up immediately.Is this still an issue with current stable nuxt releases? Or can it be closed?
As an alternative of
vite.server.watch.usePollingoption, you can add this to your Shell profile (.bashrc/.zshrc, …) :This will do the same but be applied for every project through this environment variable.
This can be suitable until we find a better solution to this issue.
Encountered same issue (I’m on WSL2 but my code is on the Subsystem), fixed with
vite.server.watch.usePolling.Reproduction
Then changes
ref('a')toref('b')in your editor, and save.On my computer, it won’t correctly trigger HMR client side.
Thanks for the validation, was feeling a little crazy that I was the only one with the issue despite my being able to reproduce it consistently… in fact I can’t NOT reproduce it 🤣