-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 HMR in static build + @import HMR #2440
Conversation
🦋 Changeset detectedLatest commit: 2899856 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 |
Closes #2317 |
✔️ Deploy Preview for astro-docs-2 ready! 🔨 Explore the source changes: 2899856 🔍 Inspect the deploy log: https://app.netlify.com/sites/astro-docs-2/deploys/61eed9348e238e00071ddc23 😎 Browse the preview: https://deploy-preview-2440--astro-docs-2.netlify.app/en/guides/markdown-content |
18179e9
to
88ff373
Compare
Upstream PR: vitejs/vite#6589 |
function cleanUrl(pathname) { | ||
let url = new URL(pathname, location); | ||
url.searchParams.delete('direct'); | ||
return url.pathname + url.search; | ||
} |
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.
Would you add /** comment */
above this to describe why it’s needed?
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.
Remember that this is Vite built code and will change when/if we update. But yeah I can for now.
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.
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.
👍
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.
Looks good.
I’ve left one comment about documenting an addition. It might be covered under "Upstream Vite fix required, PR in flight."?
I wish I knew more about client.mjs
in general. I actually did not know we pushed any JS to the browser. Is this only for HMR? Is this copied from the Vite bistro? Will this go away or need to move once we are using Vite proper?
Yeah it's just for HMR. We are vendoring vite at the moment due to some upstream bugs. Once those are fixed we will have it as a dependency instead. |
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.
LGTM with 1 comment
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.
Some nit comments, but ready otherwise. 🚀
children: '', | ||
}); | ||
scripts.add({ | ||
props: { type: 'module', src: new URL('../../runtime/client/hmr.js', import.meta.url).pathname }, |
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 didn’t realize src
is a file system path. TIL.
@@ -249,7 +261,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO | |||
const tags: vite.HtmlTagDescriptor[] = []; | |||
|
|||
// dev only: inject Astro HMR client |
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.
nit: Should this comment be amended?
// When using this flag CSS because <link> and therefore goes through Vite's | ||
// CSS pipeline. We don't need to transform here. |
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.
When using this flag CSS because and therefore...
I’m having trouble understanding this. Could it be written differently?
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.
yeah, i'll amend it.
function cleanUrl(pathname) { | ||
let url = new URL(pathname, location); | ||
url.searchParams.delete('direct'); | ||
return url.pathname + url.search; | ||
} |
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.
👍
works differently.
* Fix HMR in static build + @import HMR * Changeset * Add a comment on what cleanUrl is doing * Running prettier * Improve comments on how the static build compilation works differently.
Changes
Testing
Docs
N/A bug fix