Fix docs demos losing Panda's margins to Starlight's reset#111
Merged
Conversation
Both Panda and Starlight ship layered CSS, and a cascade layer's position
is fixed the first time its name is seen — so the docs pages were ordering
the two by accident: Panda's five layers registered first (from panda.css),
putting every `starlight.*` layer above every Panda one.
Starlight's `@layer starlight.reset` sets `* { margin: 0 }`, which then beat
Panda's margin utilities inside the live demos. On TextInput that dropped the
`mt: '-1'` tucking a Field's status message under its input: the message sat
4px lower and detached from its control, unlike the same story in Storybook.
Order the layers explicitly instead, splitting Panda's around Starlight's
rather than promoting them wholesale (which unstyles the docs — Panda's
preflight would outrank Starlight's prose). Panda's `reset`/`base`/`tokens`
stay below, so Starlight keeps the last word over its own chrome; `recipes`
and `utilities` go above, and every rule in them is selected by a `silver-*`
class that only the demos and the site's own islands carry.
Verified in a headless browser against the built site: the status message now
computes `margin-top: -4px` on the docs, matching Storybook exactly, and the
prose pages are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The bug
On the docs site,
TextInput's status message sits 4px too low and detaches from the input it belongs to. The same story in Storybook is correct — so this is docs-site-specific, not a component bug.Cause
Both Panda and Starlight ship layered CSS, and a cascade layer's position is fixed the first time its name is seen — so the docs pages were ordering the two by accident. Panda's layers register first (from
panda.css), which puts everystarlight.*layer above every Panda one:Starlight's
@layer starlight.resetsets* { margin: 0 }, which therefore beats Panda's margin utilities inside the live demos. OnTextInputthat silently drops themt: '-1'inField.recipe.tsthat tucks a status message under its control.This was never specific to
TextInput— it flattened every Panda margin utility in every demo.TextInputis just where it's visible.Fix
Order the layers explicitly, in
site/src/styles/layers.css(loaded first, since a statement only decides the order if it's registered before the sheets it names).The old
astro.config.tscomment warned against an@layerstatement, and it was right about the naive one: promoting Panda's layers wholesale puts its preflight above Starlight's prose and unstyles the docs. So this splits Panda's layers around Starlight's instead:reset,base,tokensstay below — Panda's global layers, so Starlight keeps the last word over its own chrome and prose.recipes,utilitiesgo above — every rule in them is selected by asilver-*class, which only the demo components and the site's own islands carry, so they can't reach Starlight's markup but do beat its reset.Verification
Measured in a headless browser against the built site (not just dev), comparing computed styles to the same Storybook story:
margin-top0px-4px-4pxPadding, font size, and line-height already matched and are unchanged. Screenshotted the prose-heavy pages (Getting started, Theming) and a component page to confirm the thing the old comment warned about: Starlight's headings, prose spacing, sidebar, and code blocks are all untouched.
Tests
site/src/styles/layer-order.test.tspins the properties that make this work, each of which could otherwise regress silently (the demos would just quietly render wrong):recipes/utilitiesrank above everystarlight.*layer;reset/base/tokensstay below.style/layers.cssStarlight itself ships, so a version bump that adds a layer fails here rather than in the rendered demos. (An unnamed layer registers on first use and lands last, aboveutilities, undoing the fix.)layers.cssis first incustomCss.Full suite green (2295 tests), lint + typecheck clean, site build + smoke passes.
🤖 Generated with Claude Code