-
Notifications
You must be signed in to change notification settings - Fork 935
Inject HMR code in Worker entry file #10001
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
Conversation
🦋 Changeset detectedLatest commit: bf90adb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
65f7f4d
to
627f2bb
Compare
I'm looking at the code but I'm not familiar with the full extent of the HMR setup in Vite. Does this do more than what I'd do if I added the HMR snippet in my entry myself? Because adding it, while it seems to improve stability somewhat, definitely does NOT fix HMR entirely in large application. Its still very uninstable with just that snippet. I can't get together a reproduceable sample without shipping my entire app (not open source unfortunately). But looking at the behavior, the instant I hit save on my file, I see the HMR message in the terminal. I also see my app's page in the browser flicker a few times as the various HMRed impacted file get processed. I see network chatter as the files get loaded, especially the CSS. And then nothing happens. My theory is because the Cloudflare Vite plugin rebundle the whole app (correct me if that's not true, its what folks in the Discord are saying), it takes several seconds to finish bundling, but the HMR step seem to "complete" long before that, so the changes don't get picked up. This is all uneducated guesses as best, but just adding the HMR code doesn't seem to do much. If I use a small app like the RR7 template for Cloudflare, then it works 100% of the time, but that app builds almost instantly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how this could improve the performance on code change. But I wonder if this addresses the issue you mentioned in #9518 (comment) as it might just making it less likely to happen?
Yep, I agree we shouldn't close the issue yet. This is an improvement rather than a fix and more investigation is still needed. |
eecb086
to
bf90adb
Compare
Fixes #000.
This transforms the Worker entry file to inject an HMR boundary. By providing an HMR boundary at the root, we ensure that the full module graph is not invalidated on code changes. Ideally, frameworks should be adding server HMR code at route boundaries but React Router does not currently do this. This follows discussion with the Vite team and they have also merged a PR to update the docs (vitejs/vite#20401).
From feedback gathered from users, it appears this change fixes the issues experienced in #9518. I believe this may be because HMR updates are queued (https://github.com/vitejs/vite/blob/3e81af38a80c7617aba6bf3300d8b4267570f9cf/packages/vite/src/module-runner/hmrHandler.ts#L25) whereas full reloads are not (https://github.com/vitejs/vite/blob/3e81af38a80c7617aba6bf3300d8b4267570f9cf/packages/vite/src/module-runner/hmrHandler.ts#L54). If this turns out not to be the case then we can reopen the issue.