Skip to content

CSS graph traversal can cross page boundaries via astro:i18n and leak styles between pages #16115

@riderx

Description

@riderx

Astro version

Reproduced on current main (package version 6.1.1 in this checkout).

What happened?

A page-only import of astro:i18n can cause CSS from unrelated pages to be attached to another page during build.

This was originally reported in Starlight as withastro/starlight#3787, but the bug reproduces in Astro without Starlight.

Reproduction

Using current main, create:

  • a website-only Header.astro that imports getRelativeLocaleUrl from astro:i18n
  • a SiteLayout.astro that imports site.css
  • a DocsLayout.astro that imports docs.css
  • /src/pages/index.astro using SiteLayout
  • /src/pages/docs/index.astro using DocsLayout

With build.inlineStylesheets = "never", /index.html incorrectly receives both the site stylesheet and the docs-only stylesheet.

Expected behavior

/index.html should only include the stylesheet reachable from the site page graph.

Root cause

While tracing this in packages/astro/src/core/build/plugins/plugin-css.ts, the CSS parent walk for docs.css continues past the real docs page into virtual:astro:pages and astro:config/server, then comes back down through astro:i18n into the unrelated site entrypoint. That allows CSS from one page graph to leak into another.

I have a minimal fixture and fix prepared and will link the PR here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions