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

Improve Astro style HMR for imported styles #10166

Merged
merged 4 commits into from
Feb 22, 2024
Merged

Improve Astro style HMR for imported styles #10166

merged 4 commits into from
Feb 22, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Feb 20, 2024

Changes

Fixes #9262

This PR removes some hacks needed before Vite 5.1. Now with Vite 5.1, we can register style dependencies directly to the Astro style virtual module instead, e.g. /src/pages/index.astro?astro&type=style&index=0&lang.css. We can more better prevent circular deps that caused vitejs/vite#15585 and some tailwind issues.

The result is that CSS HMR should be more granular and simpler, but in this PR I had to leverage astroFileToCompileMetadata still in HMR to invalidate the metadata correctly, so that the Astro style virtual module can re-compile the new CSS.

Testing

Added a new test and made sure HMR don't refresh for styles.

Docs

m/a. bug fix.

Copy link

changeset-bot bot commented Feb 20, 2024

🦋 Changeset detected

Latest commit: 1848080

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 Feb 20, 2024
@bluwy
Copy link
Member Author

bluwy commented Feb 22, 2024

@ematipico I added some comments since your last review explaining some things better. Appreciate if you can take another look!

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you for adding more context to how hmr internally works!

@bluwy bluwy merged commit 598f30c into main Feb 22, 2024
13 checks passed
@bluwy bluwy deleted the better-css-hmr branch February 22, 2024 14:19
@astrobot-houston astrobot-houston mentioned this pull request Feb 22, 2024
log101 pushed a commit to log101/astro that referenced this pull request Feb 23, 2024
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.

Style-only changes in .astro files don't use HMR consistently
3 participants