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.
Astro version
Reproduced on current
main(package version6.1.1in this checkout).What happened?
A page-only import of
astro:i18ncan 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:Header.astrothat importsgetRelativeLocaleUrlfromastro:i18nSiteLayout.astrothat importssite.cssDocsLayout.astrothat importsdocs.css/src/pages/index.astrousingSiteLayout/src/pages/docs/index.astrousingDocsLayoutWith
build.inlineStylesheets = "never",/index.htmlincorrectly receives both the site stylesheet and the docs-only stylesheet.Expected behavior
/index.htmlshould 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 fordocs.csscontinues past the real docs page intovirtual:astro:pagesandastro:config/server, then comes back down throughastro:i18ninto 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.