fix: coerce NaN Lab/OKLab channels to 0 in parseColor#351
Open
sarathfrancis90 wants to merge 1 commit into
Open
fix: coerce NaN Lab/OKLab channels to 0 in parseColor#351sarathfrancis90 wants to merge 1 commit into
sarathfrancis90 wants to merge 1 commit into
Conversation
color-mix() resolved at compile time by lightningcss can yield NaN chromaticity channels for degenerate mixes (e.g. mixing black with transparent in oklab). Passing NaN to colorjs.io produced an invalid color string like "#NaNNaNNaN80" that React Native silently discards, so utilities such as Tailwind's bg-black/50 rendered with no background. Treat NaN channels as 0 (a missing component per CSS Color 4) for the lab/lch/oklab/oklch cases, so the example resolves to nativewind#80. Fixes nativewind#317
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.
Summary
Fixes #317.
color-mix()is resolved at compile time by lightningcss. For a degeneratemix the result can have
NaNchromaticity channels — mixing#000withtransparentin oklab givesoklab(0 NaN NaN / 0.5), because black has nochromaticity to interpolate.
parseColorpassed thoseNaNcoords straightto colorjs.io, which serialized them to
"#NaNNaNNaN80". React Nativesilently discards an invalid color string, so utilities like Tailwind's
bg-black/50rendered with no background.Fix
The
lab/lch/oklab/oklchcases inparseColor(src/compiler/declarations.ts)now coerce each channel through a small
nanToZerohelper. A missing colorcomponent is
0per CSS Color 4, sooklab(0 NaN NaN / 0.5)becomesoklab(0 0 0 / 0.5)= black at 50% alpha, serializing to#00000080.Testing
Added a regression test in
src/__tests__/native/color-mix.test.tsxforcolor-mix(in oklab, #000 50%, transparent). It fails onmain(
Received "#NaNNaNNaN80") and passes with the fix ("#00000080").yarn test,yarn typecheckandyarn lintall pass.