Missing styles due to head propagation issue #13724
Labels
- P4: important
Violate documented behavior or significantly impacts performance (priority)
feat: rendering
Related to prop serialization, html escaping, and framework components (scope)
pkg: astro
Related to the core `astro` package (scope)
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When an integration or Starlight plugin inject dynamic routes, we are noticing in Starlight that some styles can end up missing from the head for content collection content rendered by Starlight in development mode only.
It looks like the issue is quite related to some architecture choices used in Starlight and how the
astro:content
import seems to be key in handling head propagation correctly.The reproduction I shared (also available in https://github.com/HiDeoo/astro-cc-head-propagation-repro) can seem a bit weird at first but is meant to reproduce a similar setup to what we have in Starlight and reproduce the issue without the need to add Starlight in the mix.
I'm sharing below my investigation notes if it can help but head propagation is not something I worked a lot with in the past and only had a basic understanding of it before looking into this issue. I might be missing some details or not fully understanding how it works.
Click to see my notes
/[...slug]
astro:content
import automatically gets apropagation
metadata attached to it and flagged asin-tree
(aka. another component within this component's dependency tree appends head content.)vite-plugin-head
resolves an ID for a module which contains thepropagation
metadata sets toin-tree
, it will propagate that metadata up to all importers/parentsHere is a simplified version of the Starlight architecture:
routes/static/index.astro
(entry route)<CommonPage>
fromroutes/common.astro
<Page>
fromcomponents/Page.astro
utils/routing/data
(this imports and useastro:content
torender()
a CC entry)components/StarlightPage.astro
(custom page component)<Page>
fromcomponents/Page.astro
utils/starlight-page
utils/routing/data
When multiple dynamic routes are present (e.g. injected by a plugin that also render
<StarlightPage>
), the first route that gets resolved will properly detect the deeply nested and sharedastro:content
import and propagate the metadata up. Altho, due to the shared and nestedastro:content
import, the second one will never trigger the CCin-tree
propagation for that component tree (astro:content
imported fromutils/routing/data
is already resolved and it's skipped?), and can lead to missing styles.For example, with Starlight
[...slug]
route, if a plugin inject the[...skug]
route, propagation for CC content handled by Starlight will not happen (asskug
will end up beforeslug
). Renaming that plugin route to[...smug]
will fix the issue.It looks like a workaround for Starlight would be to move our
astro:content
call torender()
to something likeroutes/common.astro
which would end up adding a differentastro:content
import which would workaround that issue.What's the expected result?
No missing styles.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-qpue1z55?file=src%2Fpages%2F%5B...slug%5D.astro
Participation
The text was updated successfully, but these errors were encountered: