Skip to content

fix(compiler): omit absent color-mix weights from serialized descriptors - #579

Merged
danstepanov merged 4 commits into
nativewind:mainfrom
sammoore:fix/color-mix-omitted-weights
Nov 20, 2026
Merged

danstepanov merged 4 commits into
nativewind:mainfrom
sammoore:fix/color-mix-omitted-weights

Conversation

@sammoore

Copy link
Copy Markdown
Contributor

Supersedes #464 and #511, keeping both authors' commits, with the following modifications:

Fixes #481, nativewind/nativewind#1870.

Problem

Tailwind 4 compiles an opacity modifier on a CSS-variable color (bg-brand/10, text-white/50) to a color-mix() with a single weight:

color-mix(in oklab, var(--color-white) 50%, transparent)

parseColorMix emitted its arguments in five fixed slots, [space, left, left%, right, right%], and left undefined in the slot for an omitted weight. Metro's getNativeInjectionCode serializes the stylesheet with JSON.stringify, which turns that undefined into null. The native resolver doesn't consume a null weight, so it rejects the whole value and the element renders with no color. This is a regression from 3.0.7, introduced when #451 made the resolver stricter.

Either weight can be the omitted one:

CSS main on native this branch
color-mix(in oklab, var(--white) 50%, transparent) no color rgba(255, 255, 255, 0.5)
color-mix(in oklab, var(--white), transparent 75%) no color rgba(255, 255, 255, 0.25)
color-mix(in oklab, var(--white), transparent) no color rgba(255, 255, 255, 0.5)

Existing tests didn't catch this. registerCSS injects the stylesheet object directly, without serializing it, and resolveValue filters undefined out of descriptor arrays.

Solution

parseColorMix emits only the arguments that are present, so there's no hole left to serialize. The argument order is unchanged, and the resolver (color-mix.ts) already handles a missing optional weight when the next argument is a color or the list ends.

The filter runs once per color-mix() at compile time. Nothing is added to the runtime path, and the serialized output is slightly smaller.

Tests

src/__tests__/native/color-mix.test.tsx (3 cases, from #511). Each case compiles real CSS with inlineVariables: false, round-trips the stylesheet through JSON.parse(JSON.stringify(...)) the same way Metro's injection does, injects it with StyleCollection.inject, and renders a View. The cases are left weight only, right weight only, and neither weight.

  • All 3 fail on main and pass with the fix.
  • Removing the .filter fails all 3.
  • Filtering only the trailing weight fails the 2 cases with no left weight.

#511's author also reproduced the bug in a physical Android release build on 3.1.0-rc.0.

Not included

Peek-A-Booo and others added 4 commits November 19, 2026 18:43
Keep only the compiler-side fix, written as a filter on the existing
argument list, and the serialized-injection regression test.

Drop the runtime null branch: with the compiler no longer emitting holes
it was unreachable for fresh builds, and it let the regression test pass
whether or not the compiler fix was present. Drop the compiler test that
asserted on the internal stylesheet layout; the end-to-end test covers
the same cases through Metro's JSON path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D4jU1dT613ZBytY8eaFjgE
@danstepanov
danstepanov merged commit 2438829 into nativewind:main Nov 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants