Closed
Labels
- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)
Description
Astro Info
Astro v6.0.8
Node v24.11.0
System Linux (x64)
Package Manager pnpm
Output server
Adapter @astrojs/node
Integrations route-gen
partial-hoist
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Astro 6.1.0 introduced a breaking change in how export const partial = true affects CSS bundling in production builds. Pages that import partials (which themselves import styled components) now have missing CSS in production, while dev mode works correctly.
What's the expected result?
Production Build (Astro 6.0.8):
CSS from ResultsTable is inlined in a <style> tag ✅
Table renders with correct styling
Dev Mode (all versions):
Works correctly (Vite includes all CSS dynamically) ✅
Production Build (Astro 6.1.0+):
CSS from ResultsTable is completely missing ❌
HTML has scoped attributes (e.g., data-astro-cid-b5yldnly) but no corresponding styles
Table renders completely unstyled
Link to Minimal Reproducible Example
https://github.com/AceCodePt/astro-partial-css-bug
Participation
- I am willing to submit a pull request for this issue.
Metadata
Metadata
Assignees
Labels
- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)
Activity
AceCodePt commentedon Apr 12, 2026
Reproduction Steps
pnpm install(installs Astro 6.1.5)pnpm builddist/index.html- CSS is missingpnpm add astro@6.0.8 --save-exactpnpm buildagaindist/index.html- CSS is now inlinedRoot Cause Analysis
Astro 6.0.8 Behavior:
export const partial = truewas treated as a hint for optimization, but CSS was still included transitively in production builds when a page imported the partial.Astro 6.1.0+ Behavior:
export const partial = trueis now strictly enforced during production builds:ResultsTable) is also excludedWhy This is a Breaking Change
Workarounds
Option 1: Remove
export const partial = true- export const partial = true;Option 2: Force CSS bundling with anonymous import
Option 3: Downgrade to Astro 6.0.8
Suggested Fix
Option A: Restore 6.0.8 Behavior (Least Breaking)
Treat
export const partial = trueas an optimization hint, but still include CSS transitively when a page imports the partial.Option B: Add Build Warning
If a page imports a partial with
export const partial = true, emit a warning:Option C: Add Configuration Option
astrobot-houston commentedon Apr 12, 2026
I was able to reproduce this issue. The root cause is a regression introduced in
astro@6.1.3(not 6.1.0 as reported) by commit12602a907c— "fix: stop CSS traversal at page boundaries (#16116)". That commit added amoduleIsTopLevelPagecheck to the CSS build graph traversal to fix a CSS leak between unrelated pages, but it inadvertently treats partial pages as CSS boundaries even when they are imported as components by other pages. Because partials are registered as top-level pages in Astro's routing system (imported by the\0virtual:astro:page:virtual module), the CSS walk stops at the partial boundary and never propagates its CSS (or its transitive dependencies' CSS) to the importing page.I was able to fix this issue. The fix refines the
isBuildCssBoundaryfunction inpackages/astro/src/core/build/plugins/plugin-css.tsto check whether a top-level page has importers other than the virtual page module. If it does, it's being used as a component (e.g. a partial imported by another page), so it should not act as a CSS boundary — allowing CSS to propagate through to the importing page. View Suggested FixPriority P4: important. This is a production-only regression that silently drops CSS for any page that imports a partial with
export const partial = true. It violates documented behavior (dev/prod parity), produces no warnings, and affects any user who adopted the partial page pattern — a supported Astro feature. While workarounds exist (removing the partial export or adding manual CSS imports), the silent failure and dev/prod mismatch make this a significant issue.Full Triage Report
Reproduction
The issue reproduces when a page imports a partial (a page with
export const partial = true) that itself imports styled components. In production builds (astro build), the CSS from the partial and its transitive dependencies is completely missing from the output HTML. Dev mode works correctly because Vite handles CSS dynamically.Root Cause
hasAssetPropagationFlag(only?astroPropagatedAssets)isPropagatedAssetBoundary(identical logic, renamed)isBuildCssBoundary(addsmoduleIsTopLevelPagecheck)The breaking commit is
12602a907c("fix: stop CSS traversal at page boundaries (#16116)"), released inastro@6.1.3. It correctly fixed a CSS leak bug between unrelated pages but treated all top-level pages — including partials used as components — as CSS boundaries.Key insight
Partial pages are simultaneously:
\0virtual:astro:page:virtual module for routingThe
isBuildCssBoundaryfunction only checked condition (1), not condition (2).Fix
The fix modifies
isBuildCssBoundaryinpackages/astro/src/core/build/plugins/plugin-css.ts:34-46to check whether the page module has importers beyond the virtual page module. If a non-virtual importer exists, the page is being used as a component, so it should not be treated as a CSS boundary:This preserves the original CSS leak fix (standalone pages still act as boundaries) while allowing CSS to propagate through partials imported as components.
This report was made by an LLM. Mistakes happen, check important info.
leefreemanxyz commentedon Apr 12, 2026
I'm also experiencing this issue, though without using the
export const partial = true- astrobot-houston's assessment rings true on the face of it.ErikSom commentedon Apr 17, 2026
Also hitting this on Astro 6.1.7, no partial = true involved.
Setup:
Layout.module.css with global rules (html, body { margin: 0; font-family: ... }, :root, @import for Google Fonts)
Imported as side-effect in Layout.astro: import "./Layout.module.css"
Dev: works. CSS applied, fonts load.
Prod build: all global selectors and the @import are missing from the output. html, body { margin: 0 } is gone (default 8px body margin appears), @import for Google Fonts is gone (falls back to system fonts). Confirmed by grepping dist/_astro/*.css. No googleapis, no font-optical-sizing. * { box-sizing } from the same file does survive.
Workaround: Downgrading to astro@5.17.1 restores everything. The full file gets inlined in a <style> tag in the built HTML as before.
Same class of bug as described (dev/prod mismatch, silent, CSS dropped), just triggered by a plain side-effect .module.css import rather than the partial path.
0xbejaxer commentedon Apr 20, 2026
Implemented a fix in #16415 that follows the triage direction here.
What was changed:
isBuildCssBoundarynow treats top-level pages as a hard CSS boundary only when they are imported exclusively by Astro's virtual page modulepartialthat imports a styled component, asserting the produced build output includes that component's scoped CSSPR: #16415
CI status: green on latest commit.
chore: remove @utrecht/root-react
chore: remove @utrecht/root-react
chore: upgrade Astro to 6.2.2 (#4115)