bug: dark-mode @media block in tokens.css does not apply when loaded via @import in iOS Safari #4
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
After adopting
@bchen/uiin buchinese, the hamburger menu panel (background: var(--bg-elevated)) still renders white in iOS Safari dark mode. The light-mode value (var(--gray-50)=#fafafa) is being applied, which means the light-mode ":root" block fromtokens.css" IS loading correctly — but the@media (prefers-color-scheme: dark)` block inside the same file is not overriding it.Root cause hypothesis
The current
dist/tokens.cssputs both light and dark declarations in a single file:Consuming projects load it via CSS
@import:iOS Safari has historically been inconsistent about applying
@mediablocks that live inside@imported stylesheets, especially when the import path is a vendor/static asset URL rather than a same-directory relative path. The light-mode:rootblock applies (it has no condition), but the conditional dark-mode block does not.The more reliable approach is to move the media condition to the
@importcall itself rather than inside the imported file, which is fully specified behaviour and has broader engine support:Proposed fix
Split
dist/tokens.cssinto two files:dist/tokens.css— light-mode:root {}block only (no@media)dist/tokens-dark.css— dark-mode:root {}values only (no@mediawrapper — the condition goes on the@import)Add
"./tokens-dark.css"to theexportsmap inpackage.json.Consuming projects update their import:
This shifts the media condition from inside the file to the
@importcall, which is the spec-correct and engine-consistent way to conditionally apply an imported stylesheet.Files to touch
dist/tokens.css— remove@media (prefers-color-scheme: dark)blockdist/tokens-dark.css— new file, dark-mode:root {}onlypackage.json— add"./tokens-dark.css"exporttests/tokens.test.ts— update / add tests for both files