Skip to content

Fix CSS updates when adding/removing style tags#15133

Merged
ematipico merged 3 commits intomainfrom
hd/fix-dev-css-module-invalidation
Feb 4, 2026
Merged

Fix CSS updates when adding/removing style tags#15133
ematipico merged 3 commits intomainfrom
hd/fix-dev-css-module-invalidation

Conversation

@HiDeoo
Copy link
Copy Markdown
Member

@HiDeoo HiDeoo commented Jan 7, 2026

Changes

Initially reported on Discord, this PR fixes an issue where adding or removing <style> tags in Astro components would result in no visual update of styles during development, unless the dev server was restarted.

  • Repro
  • After invalidating modules in the astro:hmr-reload Vite plugin, if one of the invalidated modules is the virtual module of a page, the associated virtual module for a dev CSS import is not invalidated.
  • This PR checks the list of invalidated modules for any page virtual modules, and invalidates the associated dev CSS virtual modules as well.
  • This is not done in the vite-plugin-css hotUpdate plugin hook as initially suggested by Matthew as it would require recursively checking all modules importers for page virtual modules, whereas a similar recursion is already done when calling invalidateModule() which gives us back the list all affected modules that we can iterate over.

Open to suggestions as I may not have the full context over the new vite-plugin-css implementation and may have gone about this the wrong way.

Testing

I added new E2E tests to simulate adding and removing style tags in an Astro component and verifying that the styles are updated.

Docs

This is a bug fix; no doc updates are needed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: bc70d76

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 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 7, 2026

⚠️ Package Trust Level Decreased

Caution

Decreased trust levels may indicate a higher risk of supply chain attacks. Please review these changes carefully.

📦 Package 🔒 Before 🔓 After
@cloudflare/kv-asset-handler trusted-with-provenance none
@cloudflare/unenv-preset trusted-with-provenance none
workerd trusted-with-provenance none
@sveltejs/vite-plugin-svelte-inspector trusted-with-provenance provenance
@sveltejs/vite-plugin-svelte trusted-with-provenance provenance
miniflare trusted-with-provenance none
youch provenance none
@cloudflare/workerd-darwin-64 trusted-with-provenance none
@cloudflare/workerd-darwin-arm64 trusted-with-provenance none
@cloudflare/workerd-linux-64 trusted-with-provenance none
@cloudflare/workerd-linux-arm64 trusted-with-provenance none
@cloudflare/workerd-windows-64 trusted-with-provenance none
wrangler trusted-with-provenance none

@HiDeoo HiDeoo marked this pull request as ready for review January 7, 2026 16:34
@HiDeoo HiDeoo mentioned this pull request Jan 9, 2026
10 tasks
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 27, 2026

Merging this PR will degrade performance by 17.07%

⚡ 7 improved benchmarks
❌ 1 (👁 1) regressed benchmark
✅ 1 untouched benchmark

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Build: hybrid site (static + server) 11 s 8.4 s +30.13%
Simulation Rendering: streaming [false], .mdx file 702.3 ms 590.1 ms +19.01%
👁 Simulation Rendering: streaming [false], .md file 1.3 ms 1.5 ms -17.07%
Simulation Rendering: streaming [false], .astro file 616.5 ms 330.4 ms +86.58%
Simulation Rendering: streaming [true], .astro file 615.2 ms 336.9 ms +82.6%
Simulation Rendering: streaming [true], .mdx file 709.7 ms 584.9 ms +21.35%
Simulation Build: full server site 10.8 s 8.4 s +28.67%
Simulation Build: full static site 4.7 s 3.5 s +32.22%

Comparing hd/fix-dev-css-module-invalidation (bc70d76) with main (5520f89)

Open in CodSpeed

Base automatically changed from next to main January 30, 2026 17:31
An error occurred while trying to automatically change base from next to main January 30, 2026 17:31
@matthewp
Copy link
Copy Markdown
Contributor

matthewp commented Feb 4, 2026

This was reported here: #15384

@matthewp
Copy link
Copy Markdown
Contributor

matthewp commented Feb 4, 2026

Streaming regression is odd. Going to rerun it.

@matthewp
Copy link
Copy Markdown
Contributor

matthewp commented Feb 4, 2026

It was only a .2ms diff, ignored.

@ematipico ematipico merged commit 53b125b into main Feb 4, 2026
27 checks passed
@ematipico ematipico deleted the hd/fix-dev-css-module-invalidation branch February 4, 2026 15:51
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