Ensure layer order in custom pages #3150
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Description
In a Starlight content page, we have full control over the CSS import order and we are making sure that CSS files are imported in the correct order to properly support cascade layers.
However, in custom pages using
<StarlightPage>, due to how import order for stylesheets works in Astro, we are not enforcing such order.This means that the same custom page can ends up with broken styles depending on the order in which components are imported.
For example, the following custom page work as expected as
<StarlightPage>is imported first which will import<Page>which will import the CSS files linked previously:However, having the
<AnchorHeading>or<Aside>component imported first will break the expected order as these components include styles using layers which will end up being ordered by order of usage/import.To prevent this issue in custom pages, this PR moves the user and Starlight laer definitions to a new file which is now imported first in the
<AnchorHeading>and thecomponents.tsbarrel file.To reproduce the issue locally, comment the changes in
packages/starlight/components.tsandpackages/starlight/components/AnchorHeading.astroand visit the test pages included in this PR athttp://localhost:4321/tests/test2/andhttp://localhost:4321/tests/test3/. You should see the styles broken in both pages. After applying the changes, the styles should be fixed.