-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Handle compiler breaking change #5803
Conversation
🦋 Changeset detectedLatest commit: 5f1c619 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 |
# On Windows, `svelte-preprocess` can't import `svelte/compiler`. Might be a pnpm bug. | ||
public-hoist-pattern[]=svelte |
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.
We don't have the svelte-preprocess
dependency anymore, so this can be removed.
"allowAny": [ | ||
"astro" |
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.
This is added to suppress the peer dep warning of astro-embed
, since it relied on Astro 1.0, but we want to test in 2.0.
// But we also need a fresh, uncached result to compare it to | ||
// Skip HMR if source isn't changed | ||
if (oldResult.source === source) return []; | ||
// Invalidate to get fresh, uncached result to compare it to | ||
invalidateCompilation(config, ctx.file); | ||
const newResult = await compile(); | ||
// If the hashes are identical, we assume only styles have changed | ||
if (oldResult.scope === newResult.scope) { | ||
if (isStyleOnlyChanged(oldResult, newResult)) { | ||
isStyleOnlyChange = true; | ||
// All styles are the same, we can skip an HMR update | ||
const styles = new Set(newResult.css); | ||
for (const style of oldResult.css) { | ||
if (styles.has(style)) { | ||
styles.delete(style); | ||
} | ||
} | ||
if (styles.size === 0) { | ||
return []; | ||
} |
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.
Since scope hash now derives from normalizedFilename
only, I created a isStyleOnlyChanged
function to handle it. It's a bit tedious than before, but I think leaving the HMR logic out of the compiler could be nice for now.
I also remove the styles.size === 0
handling. The logic isn't quite right given a scenario where:
oldResult
has two<style>
s- User removes one
<style>
newResult
now has one<style>
- This logic makes
styles.size === 0
and skips HMR. - BUG: The removed style's side effect isn't removed as no HMR or reload is done.
It seems that this does handle skipping HMR if no source code change, which I handled on line 37 instead.
@@ -3,7 +3,7 @@ | |||
"version": "0.0.0", | |||
"private": true, | |||
"dependencies": { | |||
"astro": "^1.0.0", | |||
"astro": "workspace:*", |
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.
The 1.0.0 was used to bypass the peer dep warning, but I found this test to use the old 1.0 code instead, breaking the compiler upgrade as both 1.0 and 2.0 code exist at the same time.
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 great, thanks!
Changes
filename
andastroGlobalArgs
optionTesting
Existing tests should pass. But I also tested the HMR issue manually to make sure it still works.
Docs
n/a. internal API