Skip to content

fix(native): resolve declarations in cascade order once an element's variables are set - #474

Merged
danstepanov merged 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:fix/deferred-declarations
Dec 2, 2026
Merged

danstepanov merged 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:fix/deferred-declarations

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A declaration whose value reads a var() resolves after every other declaration of its element, through a placeholder left at its key. Two defects on main follow from that:

  1. It resolves against the wrong target. Its closure captured applyDeclarations's shared target binding, so it checked its placeholder against whatever nested target the last declaration ended on, missed it, and left the placeholder in the style. color: var(--c); box-shadow: 1px 1px blue renders color: { color: true }, text-shadow does the same, and -webkit-line-clamp: var(--n) beside a deferred colour renders numberOfLines: { numberOfLines: true }.
  2. A deferred shorthand overwrites a later declaration. border: var(--b); border-color: blue paints the variable's colour, within a rule and across rules. border-inline-width: var(--w) does the same over a later border-inline-start-width, an earlier rule's text-shadow: var(--s) replaces a later rule's text-shadow, and animation: var(--a) replaces a later animation-duration.

Solution

  • Every rule's variables are assigned before any declaration resolves, since a var() substitutes the element's computed custom property (css-variables-1 §3). Then every declaration resolves in cascade order, so a later declaration overwrites an earlier one as browsers apply them, and no placeholder is left.
  • Transform properties keep composing through fix(transformers): resolve and cascade transform properties as browsers do #576's records once every rule is walked.
  • A runtime value that resolves to nothing still removes the property, as it does on main.

Tests

  • src/__tests__/native/deferred-declarations.test.tsx:
    • each placeholder shape, and a shadow that omits its colour beside a colour;
    • border before and after border-color, in one rule and across rules, border-inline-width before border-inline-start-width, and an earlier rule's text-shadow: var(--s) before a later rule's text-shadow;
    • a deferred transform beside an individual transform property;
    • an individual transform property before and after a transform, and beside a box-shadow;
    • a var() with no value, and a written value the runtime cannot read, over an earlier rule's value.
  • src/__tests__/native/animations.test.tsx: a written animation-duration after a variable animation, kept for the runtime with inlineVariables at its default and at false.

Verification

Every CI job passes locally on the head: lint, typecheck, yarn test, the library and web builds, commitlint, and the iOS dev build.

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

Merge order

#393 and #501 build on this, so this lands first.

It shares lines with #391, #411 and #488 (native/styles/calculate-props.ts); whichever lands second rebases. With #391, a declaration a var() leaves invalid at computed-value time resolves to unset, so the second of the two to land keeps that and drops this removal for a runtime value that resolves to nothing, which leaves one the runtime cannot read ignored.

@YevheniiKotyrlo

YevheniiKotyrlo commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Device evidence — before / after

UNFIXED — The shorthand bar is edged RED, the text keeps the default ink, and the first tile is an upright square. A var()-valued declaration resolves after every other one, so the border overwrites the later border-color, the colour lands on the wrong target, and the scale replaces the turn.

FIXED — The shorthand bar is edged BLUE like its control, the text is RED, and both tiles are diamonds. The later border-color wins, the colour resolves on its own target, and the turn composes with the scale.

before — 3.1.0-rc.0 after — with this PR

Android 16 emulator (API 36, GLES on the host GPU), 1140×2400 @ 480dpi, both frames from one run; the second tile writes the turn out and is the control. before is the published 3.1.0-rc.0 plus what my test app needs from my other patches to run: the native and native-internal subpath exports, PR 459, cascade-layer ranking, and a shim that compiles a class-qualified :root inert. after adds the rest of my open PRs, this one included. One of them shows on every screen: PR 417 narrows a var()-valued font-family to one family, so the after sets its text in the theme's face where the before falls back to the platform's.

@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 11, 2026 13:42
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as draft October 16, 2026 14:04
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 16, 2026 14:13
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as draft October 17, 2026 01:09
@YevheniiKotyrlo YevheniiKotyrlo changed the title fix(native): resolve a deferred declaration on its own target, in cascade order fix(native): resolve every declaration in cascade order once the element's variables are assigned Oct 17, 2026
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 17, 2026 03:15
@YevheniiKotyrlo YevheniiKotyrlo changed the title fix(native): resolve every declaration in cascade order once the element's variables are assigned fix(native): resolve declarations in cascade order once an element's variables are set Oct 17, 2026
danstepanov pushed a commit to sammoore/react-native-css that referenced this pull request Nov 20, 2026
border-inline-color: var(--c) and border-block-color: var(--c) resolved
through a runtime shorthand, which applies after every other declaration
of the element. A later edge colour on a different key then lost to it:
.a { border-inline-color: var(--c) } .b { border-inline-start-color: blue }
painted the start edge --c. Fixing that ordering is nativewind#474's job.

Each axis colour now compiles to one declaration per edge, the shape
border-inline-start-color: var(--c) already has, so a later edge colour
replaces it in cascade order without nativewind#474. Two literal tokens
(var(--a) var(--b), red var(--b)) still split onto start and end.

Dropped: a single var() that substitutes two colours (--c: red blue) no
longer splits; both edges get the list, which React Native's
normalizeColor leaves unset (no throw). Main sent the same list to
borderInlineColor / borderBlockColor. The runtime handler that covered it
is in patches/393-logical-border-color-runtime.patch, to land after nativewind#474.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
danstepanov pushed a commit to sammoore/react-native-css that referenced this pull request Nov 20, 2026
border-inline, border-block and their -start / -end forms with a var()
went through new runtime handlers. Tailwind emits none of them, and the
handlers apply after every other declaration of the element, so until
PR nativewind#474 lands a later edge longhand loses to them:
.a { border-inline: var(--b) } .b { border-inline-start-color: blue }
paints the start edge in --b's colour. Main sends the list to
borderInline* untouched, which React Native ignores without throwing.

The handlers and their tests are in
patches/393-logical-border-shorthand-var.patch, to land after nativewind#474.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as draft November 30, 2026 15:28
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the fix/deferred-declarations branch from 2507a93 to 400a4ad Compare November 30, 2026 15:39
YevheniiKotyrlo added a commit to YevheniiKotyrlo/react-native-css that referenced this pull request Nov 30, 2026
… React Native reads

- A var() per-edge style, which every Tailwind border-x-* / border-y-* width
  utility writes through --tw-border-style, drops without a warning, as a
  solid one does: its value is unknown, not a known non-solid style.
- light-dark() in border-inline, border-inline-start/-end and
  border-block-start/-end sends its dark half to the edge keys its light half
  lands on, through descriptorProperties, and a renamed longhand names its
  renamed key.
- A var() axis colour holding two colours keeps nativewind#581's one declaration per
  edge, and each edge picks its own colour from the resolved value.
- var() in border-inline, border-block and their -start/-end forms resolves at
  runtime onto the same edge keys as the literal forms, the style component
  dropped; with nativewind#474's cascade order a later edge declaration replaces its
  edge.
YevheniiKotyrlo added a commit to YevheniiKotyrlo/react-native-css that referenced this pull request Nov 30, 2026
… React Native reads

- A var() per-edge style, which every Tailwind border-x-* / border-y-* width
  utility writes through --tw-border-style, drops without a warning, as a
  solid one does: its value is unknown, not a known non-solid style.
- light-dark() in border-inline, border-inline-start/-end and
  border-block-start/-end sends its dark half to the edge keys its light half
  lands on, through descriptorProperties, and a renamed longhand names its
  renamed key.
- A var() axis colour holding two colours keeps nativewind#581's one declaration per
  edge, and each edge picks its own colour from the resolved value.
- var() in border-inline, border-block and their -start/-end forms resolves at
  runtime onto the same edge keys as the literal forms, the style component
  dropped; with nativewind#474's cascade order a later edge declaration replaces its
  edge.
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review November 30, 2026 16:33
YevheniiKotyrlo added a commit to YevheniiKotyrlo/react-native-css that referenced this pull request Nov 30, 2026
… React Native reads

- A var() per-edge style, which every Tailwind border-x-* / border-y-* width
  utility writes through --tw-border-style, drops without a warning, as a
  solid one does: its value is unknown, not a known non-solid style.
- light-dark() in border-inline, border-inline-start/-end and
  border-block-start/-end sends its dark half to the edge keys its light half
  lands on, through descriptorProperties, and so does a colour longhand,
  renamed or not.
- A var() axis colour holding two colours keeps nativewind#581's one declaration per
  edge, and each edge picks its own colour from the resolved value.
- var() in border-inline, border-block and their -start/-end forms resolves at
  runtime onto the same edge keys as the literal forms, the style component
  dropped; with nativewind#474's cascade order a later edge declaration replaces its
  edge.

@sammoore sammoore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge as-is. The new current squashed/rebased version of the PR is exactly the same cleanup I ended up with after solving the merge conflicts.

Thank you @YevheniiKotyrlo !!

…ent's variables are assigned

A declaration that reads a var() was resolved after the walk, through a
placeholder at its key, and only applied if no later declaration replaced
the placeholder. A later rule's variable was not yet assigned when an
earlier declaration was walked, and the delayed closures shared one target
binding across the rule's declarations.

Every rule's variables are now assigned before any declaration resolves, and
every declaration resolves in cascade order, so a later declaration
overwrites an earlier one as the browsers apply them and no placeholder is
left. Transform properties keep composing through nativewind#576's records once every
rule is walked. A runtime value that resolves to nothing still resets the
property.
@danstepanov
danstepanov force-pushed the fix/deferred-declarations branch from 400a4ad to c20b2e7 Compare December 2, 2026 18:29
@danstepanov
danstepanov merged commit 3158f1a into nativewind:main Dec 2, 2026
6 checks passed
danstepanov pushed a commit to YevheniiKotyrlo/react-native-css that referenced this pull request Dec 3, 2026
… React Native reads

- A var() per-edge style, which every Tailwind border-x-* / border-y-* width
  utility writes through --tw-border-style, drops without a warning, as a
  solid one does: its value is unknown, not a known non-solid style.
- light-dark() in border-inline, border-inline-start/-end and
  border-block-start/-end sends its dark half to the edge keys its light half
  lands on, through descriptorProperties, and so does a colour longhand,
  renamed or not.
- A var() axis colour holding two colours keeps nativewind#581's one declaration per
  edge, and each edge picks its own colour from the resolved value.
- var() in border-inline, border-block and their -start/-end forms resolves at
  runtime onto the same edge keys as the literal forms, the style component
  dropped; with nativewind#474's cascade order a later edge declaration replaces its
  edge.
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