fix(cloudflare): ensure HMR works when prerenderEnvironment is set to 'node'#16162
fix(cloudflare): ensure HMR works when prerenderEnvironment is set to 'node'#16162matthewp merged 5 commits intowithastro:mainfrom
prerenderEnvironment is set to 'node'#16162Conversation
🦋 Changeset detectedLatest commit: 8442198 The changes in this PR will be included in the next version bump. 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 |
matthewp
left a comment
There was a problem hiding this comment.
I think the E2E failures are real now. Need to figure out what about this change causes them to fail.
|
I wonder if that's the case, it feels more like I've just had remarkably bad luck.
|
|
It might not be this branch, #16180 fixes another flaky test. Should try again after that's merged. |
|
Finally! Thank you! 😆 |
fixes: #16141
Changes
When using @astrojs/cloudflare with the
prerenderEnvironmentoption set to'node', HMR would fail to trigger, requiring a manual browser reload.This occurred because the plugin added by the
createNodePrerenderPluginfunction utilizesdevPrerenderMiddlewareSymbol, which causes the execution environment for each file to be identified asprerender.However, Astro's core HMR plugin was designed to only execute HMR when the environment is specifically named
ssr.astro/packages/astro/src/vite-plugin-hmr-reload/index.ts
Lines 15 to 19 in 34c6b3a
To resolve this, I have updated the logic to use
isAstroServerEnvironment, ensuring that the HMR plugin functions correctly in bothssrandprerenderenvironments.Testing
As an e2e test, I added a test to verify that the page updates correctly after a file is modified.
Docs
N/A, bug fix