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

Refactor style-only HMR cache and performance #9712

Merged
merged 8 commits into from
Jan 19, 2024
Merged

Refactor style-only HMR cache and performance #9712

merged 8 commits into from
Jan 19, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jan 17, 2024

Changes

Supersedes and closes #9356

This PR changes how we detect if only the styles are changed in an Astro file, so we can only apply HMR on those styles. In contrary to #9356, this uses regexes to perform the comparisons, which is technically a bit brittle, but I think covers a fair amount of cases enough that it's worth the perf gain.

It also simplifies our caching, so it's less about caching but more of recording additional metadata from the compilation result. This way we use lesser data and memory, and avoid unintentional invalidation causing scripts and styles virtual modules to fail.

@natemoo-re Would love your thoughts on the regex approach for style-change detection. I'm happy to refactor that to something else if anyone doesn't feel comfortable about it 😄

Testing

The existing tests should pass as it's a refactor.

Docs

n/a. internal refactor.

Copy link

changeset-bot bot commented Jan 17, 2024

🦋 Changeset detected

Latest commit: cace49b

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 17, 2024
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Very clean refactor! Big fan of this approach and reducing the complexity of our previous caching system.

packages/astro/src/vite-plugin-astro/index.ts Show resolved Hide resolved
packages/astro/src/vite-plugin-astro/hmr.ts Show resolved Hide resolved
packages/astro/src/vite-plugin-astro/hmr.ts Show resolved Hide resolved
packages/astro/src/vite-plugin-astro/hmr.ts Show resolved Hide resolved
.changeset/eight-turtles-itch.md Outdated Show resolved Hide resolved
@bluwy bluwy merged commit ea6cbd0 into main Jan 19, 2024
4 checks passed
@bluwy bluwy deleted the hmr-part-2 branch January 19, 2024 08:44
@astrobot-houston astrobot-houston mentioned this pull request Jan 19, 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.

4 participants