-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix HMR propagation when imports not analyzed #7561
Conversation
Interesting problem. The fix isn't perfect because after reloading the client page, if the module was loaded before, then the HMR issue will still appear. It also works because we are only eagerly traversing static imports here
But dynamic imports could potentially be included at one point if the server is idle, breaking this fix. Would you explain a bit more about how this issue appears in vps? We could still merge it, but feels a bit writtle. I wonder if there is something better we could do here. It shouldn't be rare for your users to experience a page reload after the server starts, and then this patch is gone. |
1 similar comment
Interesting problem. The fix isn't perfect because after reloading the client page, if the module was loaded before, then the HMR issue will still appear. It also works because we are only eagerly traversing static imports here
But dynamic imports could potentially be included at one point if the server is idle, breaking this fix. Would you explain a bit more about how this issue appears in vps? We could still merge it, but feels a bit writtle. I wonder if there is something better we could do here. It shouldn't be rare for your users to experience a page reload after the server starts, and then this patch is gone. |
The original problem, for which I wrote this fix, is when the dyamically imported module defines In that case, the fix is reliable.
vps 0.4 has a custom modifier You're right - and I didn't think of that - the fix is not reliable for dynamically imported modules that don't have My proposal: I'll update the PR to add a link to our discussion (I'll also update |
Ah, it is true, if accept is defined then once it is loaded this fix will improve HMR even after reloads 👍🏼 I'm also trying to think of a way of making the other case work, but it requires communication between each client and the server and keep also track of sessions for each client. I think we should merge this PR after the code review, at least it is an approval from me. Let's try to get other team members to check it out before though (we are no longer in the beta, so we need to be very careful until we open that window again) |
PR updated & ready for review. |
Thanks for the commits. Looking forward to (help folks) build Vite/vps frameworks. |
hi :) i'm quite new to vite though, so maybe i'm doing something wrong 🤪 |
@mazerty perhaps you need to call |
thanks a lot for your reply :) |
Description
In some situations, the HMR signal hits a module that has not been analyzed.
For example, a dynamic import that is never called
const neverCalled = () => import('./dep.js')
. Here thedep.js
file is never loaded and thus never analyzed by theimportAnalysis.ts
plugin.If the HMR signal hits such non-analyzed module, then this means that the module has not been loaded.
Because it has not be loaeded there is nothing to refresh; we can and should stop the HMR propagation. Otherwise the HMR signal triggers a wrongful full page reload.
Additional context
This is a vps 0.4 release blocker. (This situation used to be an edge case with vps 0.3 but, with the new vps architecture, this is a common and problematic case.)
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).