Skip to content

Breaking Change: CSS missing in production when using 'export const partial = true' (6.1.0+) #16296

Closed

Description

@AceCodePt

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.

Activity

  1. AceCodePt commented on Apr 12, 2026

    @AceCodePt
    Author

    Reproduction Steps

    1. Clone the reproduction repo
    2. Run pnpm install (installs Astro 6.1.5)
    3. Run pnpm build
    4. Check dist/index.html - CSS is missing
    5. Downgrade: pnpm add astro@6.0.8 --save-exact
    6. Run pnpm build again
    7. Check dist/index.html - CSS is now inlined

    Root Cause Analysis

    Astro 6.0.8 Behavior:
    export const partial = true was 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 = true is now strictly enforced during production builds:

    • The partial's CSS is excluded from the page bundle
    • All transitive dependencies' CSS (like ResultsTable) is also excluded
    • This creates a mismatch between dev (works) and production (broken)

    Why This is a Breaking Change

    1. No Migration Guide: The change was not documented in release notes
    2. Silent Failure: No build warnings or errors - CSS is simply missing
    3. Dev/Prod Mismatch: Works in dev, fails in production (hardest type of bug to catch)
    4. Transitive Impact: Affects not just the partial, but all its dependencies

    Workarounds

    Option 1: Remove export const partial = true

    - export const partial = true;

    Option 2: Force CSS bundling with anonymous import

    ---
    import SearchResults from './partials/search-results';
    import './_components/ResultsTable/index.astro'; // Force CSS bundling
    ---

    Option 3: Downgrade to Astro 6.0.8

    pnpm add astro@6.0.8 --save-exact

    Suggested Fix

    Option A: Restore 6.0.8 Behavior (Least Breaking)
    Treat export const partial = true as 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:

    ⚠️  Warning: Page 'index.astro' imports partial 'search-results/index.astro'
       CSS from this partial and its dependencies will not be bundled.
       Consider removing 'export const partial = true' or adding explicit CSS imports.
    

    Option C: Add Configuration Option

    // astro.config.mjs
    export default defineConfig({
      build: {
        partialCssStrategy: 'transitive' | 'strict'
      }
    });
  2. astrobot-houston commented on Apr 12, 2026

    @astrobot-houston
    Contributor

    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 commit 12602a907c — "fix: stop CSS traversal at page boundaries (#16116)". That commit added a moduleIsTopLevelPage check 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 isBuildCssBoundary function in packages/astro/src/core/build/plugins/plugin-css.ts to 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 Fix

    Priority 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

    Version CSS walk boundary check Effect on partials
    6.0.8 hasAssetPropagationFlag (only ?astroPropagatedAssets) CSS propagates through partials ✅
    6.1.0 isPropagatedAssetBoundary (identical logic, renamed) CSS propagates through partials ✅
    6.1.3 isBuildCssBoundary (adds moduleIsTopLevelPage check) CSS blocked at partial boundary ❌

    The breaking commit is 12602a907c ("fix: stop CSS traversal at page boundaries (#16116)"), released in astro@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:

    1. Top-level pages — imported by the \0virtual:astro:page: virtual module for routing
    2. Components — imported by other pages as regular Astro components

    The isBuildCssBoundary function only checked condition (1), not condition (2).

    Fix

    The fix modifies isBuildCssBoundary in packages/astro/src/core/build/plugins/plugin-css.ts:34-46 to 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:

    function isBuildCssBoundary(id: string, ctx: { getModuleInfo: GetModuleInfo }): boolean {
        if (isPropagatedAssetBoundary(id)) return true;
        const info = ctx.getModuleInfo(id);
        if (!info || !moduleIsTopLevelPage(info)) return false;
        const allImporters = info.importers.concat(info.dynamicImporters);
        const hasNonVirtualImporter = allImporters.some(
            (imp) => !imp.includes(VIRTUAL_PAGE_RESOLVED_MODULE_ID),
        );
        return !hasNonVirtualImporter;
    }

    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.

  3. added
    - P4: important
    pkg: astro
    and removed
    triage: needs triage
    on Apr 12, 2026
  4. leefreemanxyz commented on Apr 12, 2026

    @leefreemanxyz

    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.

  5. ErikSom commented on Apr 17, 2026

    @ErikSom

    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.

  6. 0xbejaxer commented on Apr 20, 2026

    @0xbejaxer
    Contributor

    Implemented a fix in #16415 that follows the triage direction here.

    What was changed:

    • isBuildCssBoundary now treats top-level pages as a hard CSS boundary only when they are imported exclusively by Astro's virtual page module
    • If a top-level page (including partial pages) has non-virtual importers, CSS traversal is allowed so transitive styles propagate to the importing page
    • Added a regression fixture/test covering a page importing a partial that imports a styled component, asserting the produced build output includes that component's scoped CSS

    PR: #16415
    CI status: green on latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantpkg: astro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions