-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
CSS graph traversal can cross page boundaries via astro:i18n and leak styles between pages #16115
Description
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.astrothat importsgetRelativeLocaleUrlfromastro:i18n - a
SiteLayout.astrothat importssite.css - a
DocsLayout.astrothat importsdocs.css /src/pages/index.astrousingSiteLayout/src/pages/docs/index.astrousingDocsLayout
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.