Skip to content
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

Merged
merged 10 commits into from
Jan 12, 2023
Merged

Handle compiler breaking change #5803

merged 10 commits into from
Jan 12, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jan 9, 2023

Changes

  • Bump a new minor for the compiler
  • Handle compiler breaking changes
    • Use the new filename and astroGlobalArgs option
  • Fix minor styles HMR

Testing

Existing tests should pass. But I also tested the HMR issue manually to make sure it still works.

Docs

n/a. internal API

@changeset-bot
Copy link

changeset-bot bot commented Jan 9, 2023

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 9, 2023
@bluwy bluwy changed the title Update createAstro breaking change Handle compiler breaking change Jan 12, 2023
@bluwy bluwy marked this pull request as ready for review January 12, 2023 11:51
Comment on lines -13 to -14
# On Windows, `svelte-preprocess` can't import `svelte/compiler`. Might be a pnpm bug.
public-hoist-pattern[]=svelte
Copy link
Member Author

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.

Comment on lines +70 to +71
"allowAny": [
"astro"
Copy link
Member Author

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.

Comment on lines -30 to -45
// 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 [];
}
Copy link
Member Author

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:

  1. oldResult has two <style>s
  2. User removes one <style>
  3. newResult now has one <style>
  4. This logic makes styles.size === 0 and skips HMR.
  5. 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:*",
Copy link
Member Author

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.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@bluwy bluwy merged commit ae8a012 into main Jan 12, 2023
@bluwy bluwy deleted the handle-compiler-update branch January 12, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants