Skip to content

fix: preserve light-dark in custom properties - #1287

Open
TheAlexLichter wants to merge 2 commits into
parcel-bundler:masterfrom
TheAlexLichter:fix/light-dark-custom-properties
Open

fix: preserve light-dark in custom properties#1287
TheAlexLichter wants to merge 2 commits into
parcel-bundler:masterfrom
TheAlexLichter:fix/light-dark-custom-properties

Conversation

@TheAlexLichter

@TheAlexLichter TheAlexLichter commented Jun 24, 2026

Copy link
Copy Markdown

Resolves #821

This PR keeps the existing light-dark() polyfill for custom properties so old browser behavior and common design-system token patterns remain intact.

But it also adds native light-dark() @supports overrides for supporting browsers which includes correct handling for LAB/P3 fallbacks, !important, support checks like custom properties or var()/attr() fallbacks and redeclarations.

@property initial-value preserves native light-dark() as is because otherwise it would invalidate typed custom-property registration.

Main downside is more generated CSS for custom properties with light-dark() but only when targeting browsers that need the polyfill behavior.

@devongovett

Copy link
Copy Markdown
Member

I would say that's a breaking change. I know the polyfill isn't perfect, but people are relying on it anyway.

@TheAlexLichter

Copy link
Copy Markdown
Author

Back to the drawing board then. I'll try to come up with a solution that fixes light-dark() "better" while remaining backward-compatible with the current polyfill.

@TheAlexLichter
TheAlexLichter marked this pull request as draft June 24, 2026 15:11
@MoritzLost

Copy link
Copy Markdown

@devongovett @TheAlexLichter Is it a breaking change to fix something that's already broken, though?

If people are relying on this transpiler feature, they most likely are not using color-scheme in the way described in the issue, or they would've run into this bug. If they did encounter the bug, they would have to have either disabled the feature, or implemented a workaround. In either case, nothing will break when the feature is only turned off in cases where it would trigger the bug at the moment.

@devongovett

Copy link
Copy Markdown
Member

No, it's only broken in a very specific case when you set the color-scheme on a different element than the var. If you define your variables on the same element you set color-scheme it will work fine. This is a very common case, i.e. a design system usually sets it's tokens on a root-level element that also sets the color scheme. Removing this feature would break that.

Note that there is already a feature flag to disable LightDark if you want. We could consider a separate flag to disable it on vars I suppose.

@TheAlexLichter
TheAlexLichter marked this pull request as ready for review June 24, 2026 15:28
@TheAlexLichter

Copy link
Copy Markdown
Author

Tried something more sophisticated (which is slightly ugly and givesTokenList a bit more to do 🙈).

Also fine with switching to a new feature flag instead if you think that approach isnt the way.

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.

light-dark is broken when children have different color-scheme's

3 participants