Open danieltroger opened 19 hours ago
I am also having this issue! Using 4.4.2 in a project I haven't touched in awhile, come back to it and HMR is not working at all. It's also having issues with "cannot find named export XXXX in file src/pages/xxx.js" when it's clearly there.
Describe the bug
Hi, multiple members of the team I'm working in are suffering from Vite's HMR sometimes not working at all (not even full page reloads happen, the page just isn't updated). In some files in the codebase, it consistently never works.
We're using vite together with react. It's driving us crazy when it doesn't work, since we've gotten used to HMR always working, so when things don't behave as expected in the browser, we first think our code is at fault. We re-think approaches and add debug information, only to notice even that doesn't work. Then we reload the page, which unfortunately given our project size takes around 35 seconds (so it isn't a viable workaround to always reload). After a reload, our code suddenly works, and we get frustrated.
This led me to providing this reproduction, in hopes of someone knowing how to fix it. As copying files into a fresh repo didn't reproduce the bug, I have started out with the file where HMR never worked for us (
useAnimationStyling
) and spent hours painstakingly deleting files from our project.Unfortunately, the "hit rate" of the bug has gone down from 100% to ~15% in the process, yet the "minimal" reproduction contains 45 files. Most of them just contain one import and one export though.
Apparently, the bug has at least something to do with project size, as deleting a bunch of unused files (not imported at all from vite's entrypoint) from our actual repo seems to have decreased the success rate down to matching the one of the attached reproduction repo.
Please have some patience when trying to follow the reproduction steps.
Related issue: https://github.com/vitejs/vite/issues/16284 but I don't think this is the same since for us it works for some files all the time and never for some others.
Reproduction
https://github.com/danieltroger/vite-hmr-bug-repro
Steps to reproduce
git clone https://github.com/danieltroger/vite-hmr-bug-repro
cd vite-hmr-bug-repro
yarn
yarn dev
./src/lite/views/Collection/DragAndDrop/useAnimationStyling.tsx
in your editorCongratulations, you have hit the bug! When our project is in its full glory without any files deleted, this happens every time. You might have to do ~20 saves to hit it.
Here's a video of me walking through the reproduction steps (if it doesn't play, right click + save as and open it with QuickTime):
https://github.com/user-attachments/assets/19c40415-4e75-464c-bc85-e06411e5b1bf
System Info