Skip to content

fix(native): let a rule's shadow list replace an earlier rule's - #601

Merged
danstepanov merged 2 commits into
nativewind:mainfrom
sammoore:fix/shadow-list-replaces
Dec 2, 2026
Merged

danstepanov merged 2 commits into
nativewind:mainfrom
sammoore:fix/shadow-list-replaces

Conversation

@sammoore

@sammoore sammoore commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Supersedes #488 with a minor perf improvement:

  • The original PR allocated a WeakSet for every element, regardless of whether it had a shadow.
  • A single local variable is sufficient for remembering the list the rule last started

Problem

A compiled box-shadow is written one entry at a time (&.boxShadow.[0].color, &.boxShadow.[0].offsetX, …), and the walk wrote into whatever list the element already held, so a later rule's list merged into an earlier rule's instead of replacing it:

.first { box-shadow: 1px 1px 0 0 #123456, 2px 2px 0 0 #654321; }
.second { box-shadow: 3px 3px 0 0 #13579b; }

className="first second" renders two shadows, #13579b and #654321, where a browser renders #13579b alone. An outset shadow over an inset one keeps inset: true, and the same happens between two !important lists and across specificity. The same CSS resolved at runtime, through a variable that is not inlined, already replaced the list, so the result depended on whether the compiler had inlined the variable.

Solution

applyDeclarations runs once per rule. It now remembers the lists that rule starts, and the rule's first write to any other list replaces it with a new one.

Tests

src/__tests__/native/box-shadow.test.tsx: ten cascades — a list over a longer one, over an inset shadow and over one held in a variable; a list held in a variable over a literal one and over another; none over a list and a list over none; an !important list over an earlier important one and under a later normal one; and a more specific list over a later one — each run with variables inlined and resolved at runtime, and with the sheet injected as compiled and as the JSON a device receives. Each expected value is what Chromium 153, Firefox 155 and WebKit 26.6 compute for the same CSS. On main 22 of the 40 fail: every case that writes a compiled list over a list an earlier rule wrote. The other 18 — a list resolved at runtime, none, and an important list under a later normal one — pass before and after.

Verification

On Ubuntu with the workflow's steps - build, lint, typecheck, yarn test, node --test node/__tests__/*.mjs, both library builds, the web export, the unstaged-changes checks and commitlint - everything passes.

Device evidence, before and after: #488 (comment)

Not run: the iOS and Android example builds.

YevheniiKotyrlo and others added 2 commits December 2, 2026 11:37
A compiled box-shadow is written index by index, and the walk reused the
list an earlier rule had already written for the element. A later rule's
list therefore merged into it: `[green]` over `[red, blue]` rendered
`[green, blue]`, and an outset shadow over an inset one kept `inset: true`.
The same CSS resolved at runtime, through a variable, already replaced the
list. Each rule's first write to a list now starts a new one.
applyDeclarations runs once per rule on every render, and the WeakSet that
A rule writes each list's entries together, so remembering the last list
it started is enough to tell an earlier rule's list from its own.

Hermes list-bench (9 processes per case, against bench): the PR as written
is +2.5–5.9% on rules with no list and +8.6% on a list over an earlier
rule's list; this is within ±1.6% of bench on every case. Rendered styles
are identical to the PR's.
@danstepanov
danstepanov force-pushed the fix/shadow-list-replaces branch from 95902e3 to 1e9a27e Compare December 2, 2026 16:37
@danstepanov danstepanov closed this Dec 2, 2026
@danstepanov danstepanov reopened this Dec 2, 2026
@danstepanov
danstepanov merged commit d42c649 into nativewind:main Dec 2, 2026
12 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

Development

Successfully merging this pull request may close these issues.

3 participants