Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Jan 17, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

* fix(css): include styles for conditionally rendered Svelte 5 components

When Svelte 5 components are conditionally rendered (e.g., inside {#if} blocks
with an initially false condition), their styles were not being included in
production builds. This happened because:

1. Svelte 5.26+ added css.hasGlobal flag to compiler output
2. vite-plugin-svelte 5.1.0+ uses this to add cssScopeTo metadata
3. Vite 6.2+ cssScopeTo allows CSS treeshaking if the export isn't "used"

During SSR, conditionally rendered components aren't included in the server
build (tree-shaken), but they are in the client build. Astro's CSS-to-page
mapping primarily happens during the server build, so the CSS gets orphaned.

The fix adds logic in the client build's generateBundle to:
- Track which component exports are actually rendered (renderedComponentExports)
- For CSS modules with cssScopeTo metadata where the export IS rendered,
  walk up the module graph to find pages and ensure the CSS is included

Fixes #14252

* Track components from server pages
@pull pull bot locked and limited conversation to collaborators Jan 17, 2026
@pull pull bot added the ⤵️ pull label Jan 17, 2026
@pull pull bot merged commit 9a609f4 into code:main Jan 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant