Repository navigation
fix: map every logical border property onto a prop React Native reads - #393
YevheniiKotyrlo wants to merge 7 commits into
Conversation
applyDeclarations reassigned its target parameter per declaration, and a
deferred declaration's closure captured that shared binding. The closure
runs after every declaration in the rule has been walked, so it read
whatever nested target the last declaration ended on: a deferred color
beside a box-shadow checked its placeholder against the shadow entry,
missed it, and left the internal { color: true } in the style.
-webkit-line-clamp: var(--n) left { numberOfLines: true } on the prop the
same way.
Each declaration now walks into a binding of its own.
A deferred declaration resolves after every other declaration of the element, so a shorthand that resolved at runtime spread its keys over whatever a later declaration had set: border: var(--b) followed by border-color: blue painted the variable's colour, within a rule and across rules, and so did border-inline-width: var(--w) over a later border-inline-start-width. Each key belongs to the declaration that set it last (css-cascade-5 §6.4). Each element now records, per target and key, the cascade position of its last writer. A deferred shorthand learns its keys only when it resolves, so it claims them one by one and keeps the ones a later declaration holds.
d5cc8ca to
e36c560
Compare
A shadow that omits its colour takes currentcolor, which resolves as a
deferred declaration inside the shadow. On main its placeholder reaches
the style: textShadowColor: { textShadowColor: true } for a colourless
text-shadow beside a color, and color: { color: true } on a colourless
box-shadow entry under an inherited colour.
A later `text-shadow` writes its offset through `textShadowOffset.width`
and `.height`, and only the leaf was claimed, so an earlier
`text-shadow: var()` that resolved late still replaced `textShadowOffset`
whole: `.earlier { --s: 2px 2px blue; text-shadow: var(--s) }` before
`.my-class { text-shadow: 1px 1px red }` drew the red shadow at the blue
offset. A declaration written through a path now claims each key it
passes through.
The two text-shadow rows are about which declaration wins, so the colour a variable carries is written in the form a runtime reader keeps whether it serialises a named colour or not.
…ent's variables are assigned
A declaration that reads a var() was resolved after the walk, through a
placeholder at its key, so the walk had to remember which later declaration
set each key to keep a deferred shorthand off it. A placeholder is also what
an individual transform property replaced with an empty list, so
`.a { transform: var(--t) } .b { rotate: 45deg }` lost the transform.
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 the key claims are gone. A
placeholder is left only for an individual transform property, which composes
into the transform list once every rule is walked. A runtime value that
resolves to nothing still resets the property.
border-block-color wrote borderBlockColor when its edges matched and borderTopColor / borderBottomColor when they did not, so a later border-top-color sat beside the axis key instead of replacing it, and Android and iOS rank the two oppositely. Each axis colour now lands on its edge pair at every arity, and a light-dark() component opens its dark rule over the edge it feeds. A var() kept the axis colours and the six logical shorthands off the parsed path: border-inline-color: var(--c) wrote borderInlineColor, which React Native lacks, and border-inline: var(--b) reached it as a list. Each now resolves at runtime onto the same keys the compiler writes, reading as many values as the variable substitutes, as border-inline-width already does. A var() edge style drops as quietly as solid, since an unknown value is not a known non-solid one, and a runtime-parsed value that compiles to nothing declares nothing.
e36c560 to
85c6387
Compare
sammoore
left a comment
There was a problem hiding this comment.
Thanks for this! The core fix has landed in #581: your commit with follow-ups on top, squashed into 0ef4ec8 with you as co-author. border-x-*/border-y-* colours now compile to one declaration per edge (borderStartColor/borderEndColor, borderTopColor/borderBottomColor), so they're drawn on both platforms and a later edge colour wins in cascade order. That fixes the Nativewind v4 regression without #474.
#581 set aside the parts of this PR that doesn't affect Tailwind users, leaving four fixes for this PR. Could you rebase onto main and narrow it to them?
Two are independent of #474 and apply directly to main:
- Quieting the warning for
border-inline-style: var(--tw-border-style), which everyborder-x-2/border-y-2triggers. Ideally just a ~3-line warning change. light-dark()in the edge shorthands (border-inline,border-inline-start,border-block-startand so on). It can reuse thedescriptorPropertiesthat #581 added.
Two resolve at runtime, so as written they need #474:
- A
var()axis colour holding two colours (--c: red blueinborder-x-(--c)). This could work without #474 by keeping #581's one declaration per edge and having each edge pick its colour from the resolved value. var()inborder-inline/border-blockand their-start/-endforms.
Up to you how you want to group these changes (all in this PR based on #474, or what have you); I'll review them after the next release. The runtime pair can wait for #474 and/or use the per-edge approach above.


Problem
On
main:border-block-colorlands on two key sets.border-block-color: redwritesborderBlockColor, andred bluewritesborderTopColor/borderBottomColor. A laterborder-top-colorthen sits beside the axis key instead of replacing it, and Android and iOS rankborderBlockColoragainstborderTopColoroppositely, so the two platforms paint different colours.border-blockwritesborderBlockColortoo.var()keeps the axis colours and the six logical shorthands off the parsed path.border-inline-color: var(--c)writesborderInlineColor, which React Native has no prop for.border-block-color: var(--c)with--c: red bluewritesborderBlockColor: ["red", "blue"].border-inline: var(--b)reaches React Native asborderInline: [2, "solid", "red"], andborder-block-start: var(--b)asborderBlockStartthe same way.var()edge style warns.border-inline-style: var(--tw-border-style), which every Tailwind v4border-{x,s,e}-*utility emits, warns where the parsed path dropssolidquietly, andborder-block-style: dotted dashednames the inline edges in its warning.Solution
borderStartColor/borderEndColor, the block axis onborderTopColor/borderBottomColor. Each edge parses its own colour, so alight-dark()component opens its dark rule over the edge it feeds.border-block-color,border-inline-colorand the six logical shorthands resolve avar()at runtime onto the same keys, reading as many values as the variable substitutes, asborder-inline-widthalready does.var()edge style drops as quietly assolid, and a two-value edge style names its own edges.border-inline-color: inheritleft an empty style.Tests
src/__tests__/compiler/logical-borders.test.tspins every logical property on the parsed path and the runtime call eachvar()compiles to.src/__tests__/native/logical-borders.test.tsxrenders each: one key set per property under every cascade order and condition, eachvar()shorthand, a pair through onevar(), a substitution the grammar does not take, andlight-dark()on the parsed path.main, 80 of the 276 cases in these files andborders.test.tsxfail. Each of 10 mutations fails its own cases.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: #393 (comment)
Known limits
light-dark()holding avar()insideborder-block-colororborder-inline-colorreaches the runtime handler, wherelight-dark()has no runtime resolver yet; fix: resolve light-dark() at runtime from the used colour scheme #420 adds one.mainwrites both of its halves to keys React Native lacks.Merge order
This builds on #474, which resolves every declaration in cascade order, so a runtime shorthand leaves a later longhand its keys. It lands first, and this carries its commits until it does.