Skip to content

fix: wrap theme overrides in Starlight's cascade layer - #8

Merged
LukasHirt merged 1 commit into
mainfrom
fix-theme-cascade-layer
Sep 25, 2026
Merged

LukasHirt merged 1 commit into
mainfrom
fix-theme-cascade-layer

Conversation

@LukasHirt

Copy link
Copy Markdown
Contributor

The theme colors merged in the previous PR were unlayered CSS, which always beats Starlight's own layered rules regardless of selector specificity. That broke the light/dark toggle: the nav bar followed the theme correctly (untouched by my override), but the page body, sidebar, and search dialog stayed dark in light mode. Wrapping the same rules in Starlight's own @layer restores normal cascade behavior. Verified both themes and the search dialog in an actual browser before pushing.

The previous commit's :root override was unlayered CSS. Astro's
customCss is injected unlayered by default, and unlayered CSS always
wins over layered CSS regardless of selector specificity - Starlight's
own theme rules live in @layer starlight.base, so my unscoped :root
was beating its more-specific :root[data-theme='light'] rule for every
property this file touches, breaking the light/dark switch. Nav bar
correctly followed the theme (it uses --sl-color-bg-nav, which resolves
through a primitive this file never touched), while the page body,
sidebar, and search dialog all stayed dark regardless of the selected
theme, since they resolve through --sl-color-black/-gray-*, which this
file did override.

Wrapping the same rules in @layer starlight.base restores normal
cascade behavior: light mode's more specific selector now correctly
wins when active. Verified both themes, and the search dialog
specifically, in an actual browser before pushing this time.

Signed-off-by: Lukas Hirt <info@hirt.cz>
@LukasHirt
LukasHirt merged commit da34b06 into main Sep 25, 2026
6 checks passed
@LukasHirt
LukasHirt deleted the fix-theme-cascade-layer branch September 25, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant