In my project, I stop full reload by throwing an error in the handler for vite:beforeFullReload
, and then handle the HMR manually.
When I dynamic import a module, I see that it still imports the old module.
At this point, the generated code is:
import('my-module.ts')
But after I refresh manually, I see the file has changed to change the import to include ?t=XXXXX
. This causes the updated module to get imported each time after this.
i.e.
import('my-module.ts?t=XXXXX')
How can I make it so that even for the first time, the import already has ?t=XXXXX
appended to it so that a new version gets downloaded when it is imported?
The HMR is tricky imho, writing hooks for it is more mind boggling that other Vite/Rollup hooks, so I wouldn't recommend it.
The behavior of HMR you described is totally OK, works as expected. To avoid unnecessary caching just turn it off in your Devtools: