Repository navigation
Description
Before submitting a new issue
- I tested using the latest version of the library, as the bug might be already fixed.
- I tested using a supported version of react native.
- I checked for possible duplicate issues, with possible answers.
Bug summary
I came across this while narrowing #393 to the logical border cases #581 left: the logical edge shorthands sent the dark half of light-dark() to a key React Native doesn't have, and on main the physical ones do the same.
On native, light-dark() as the colour of border, border-top, border-right, border-bottom or border-left compiles its dark half to a rule keyed by the shorthand's own name (border, borderTop, borderRight, borderBottom, borderLeft). None of these is a React Native style key, so in the dark scheme the border keeps its light colour. border-color: light-dark(#2266ee, #66aaff) red writes its light half to borderTopColor and borderBottomColor and its dark half to borderColor; React Native takes an edge's own colour over borderColor, so the top and bottom edges stay light too. border-top-color: light-dark(…) switches to its dark colour.
parseBorder, parseBorderSide and the border-color branch of parseBorderColor parse the colour with parseColor, so the dark half goes to the property parseWithParser put in descriptorProperties. parseBorderBlock and the axis colours go through parseColorFor (#581), which names the keys the colour lands on.
#393 fixes the same defect for border-inline, border-inline-start/-end and border-block-start/-end. #420, which resolves light-dark() at runtime instead of writing a dark rule, fixes all six cases here: the reproducer below exits 0 on its head, bd350ee.
Library version
main at ca5e6a4 (package.json version 3.0.7)
Environment info
System:
OS: Windows 11 10.0.26300
CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor "
Memory: 131.49 GB / 255.67 GB
Binaries:
Node:
version: 26.13.1
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 4.9.2
[…]
npm:
version: 12.2.1
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
Versions:
- 10.0.19041.0
- 10.0.26100.0
IDEs:
Android Studio: AI-262.9437.185.2621.16467767
Visual Studio: Not Found
Languages:
Java:
version: 17.0.20.1
path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
Ruby: Not Found
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 19.2.3
wanted: 19.2.3
react-native:
installed: 0.86.3
wanted: 0.86.3
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not foundThe repository's .nvmrc pins Node 22.18.0; I ran this on Node 26.13.1 and not on 22.18.0.
Steps to reproduce
- Clone the reproducer branch, which is
mainat ca5e6a4 with two files added,reproduce.mjsandsrc/__tests__/native/repro-physical-border-light-dark.test.tsx:git clone --branch repro/physical-border-light-dark https://github.com/YevheniiKotyrlo/react-native-css cd react-native-css - Run
node reproduce.mjs. It runsyarn install --immutable, thenyarn teston the test file, which for each declaration renders<View className="card" />fromreact-native-css/components/Viewwith.card { color-scheme: light dark; <declaration>; }registered throughregisterCSS, reads itsstyleprop aftercolorScheme.set("light")and again aftercolorScheme.set("dark"), and records the rulescompile()writes for.card. The declarations areborder,border-top,border-right,border-bottomandborder-leftas2px solid light-dark(#2266ee, #66aaff),border-color: light-dark(#2266ee, #66aaff) red, andborder-top-color: light-dark(#2266ee, #66aaff)as the control. It prints each case and ends with one line:DEFECT: …and exit status 1 while a shorthand keeps its light colour in the dark scheme or its dark style gains a key its light style lacks;FIXED: …and 0 once each sets#66aaffon the key its light colour is on and nothing else;ERROR: …and 2 when a step fails, runs past its deadline (15 minutes, or whatREPRODUCE_STEP_MINUTESsets), or a case fails another way.
Expected: in the dark scheme each shorthand sets #66aaff on the key its light colour is on — borderColor for border, borderTopColor … borderLeftColor for the edges, borderTopColor and borderBottomColor for border-color — as border-top-color does, and adds no other key; the light scheme and the widths and styles stay as they are. reproduce.mjs then ends with FIXED: in the dark scheme border, the four physical edge shorthands and border-color set #66aaff on the key their light colour is on, and add no key and exits 0.
Actual: the dark rule of each shorthand names a key its light rule doesn't set, and the rendered colour stays #26e; reproduce.mjs exits 1:
[…]
.card { color-scheme: light dark; border-top: 2px solid light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderTopColor":"#26e","borderTopWidth":2}]}
{"s":[1,1],"d":[{"borderTop":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderTopColor":"#26e","borderTopWidth":2}
rendered, dark scheme: {"borderTopColor":"#26e","borderTopWidth":2,"borderTop":"#6af"}
dark scheme: borderTopColor "#26e", adds borderTop, where borderTopColor "#66aaff" alone is expected
[…]
.card { color-scheme: light dark; border-color: light-dark(#2266ee, #66aaff) red; }
compiled rules:
{"s":[1,1],"d":[{"borderTopColor":"#26e","borderBottomColor":"#26e","borderLeftColor":"#f00","borderRightColor":"#f00"}]}
{"s":[1,1],"d":[{"borderColor":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
{"s":[1,1],"d":[{"borderColor":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderTopColor":"#26e","borderBottomColor":"#26e","borderLeftColor":"#f00","borderRightColor":"#f00"}
rendered, dark scheme: {"borderTopColor":"#26e","borderBottomColor":"#26e","borderLeftColor":"#f00","borderRightColor":"#f00","borderColor":"#6af"}
dark scheme: borderTopColor "#26e", adds borderColor, where borderTopColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-top-color: light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderTopColor":"#26e"}]}
{"s":[1,1],"d":[{"borderTopColor":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderTopColor":"#26e"}
rendered, dark scheme: {"borderTopColor":"#6af"}
dark scheme: borderTopColor "#6af", as expected
DEFECT: in the dark scheme 6 of 6 shorthands (border, border-top, border-right, border-bottom, border-left, border-color) keep #2266ee on their colour key, and their dark colour lands on border, borderTop, borderRight, borderBottom, borderLeft, borderColor instead, while border-top-color: light-dark() switches borderTopColor to #66aaff
The run's output on main at ca5e6a4, Windows 11, Node 26.13.1, Yarn 4.9.2
System: Windows_NT 10.0.26300 x64, Node v26.13.1, Yarn 4.9.2, react-native-css 3.0.7 at aa217e8
yarn install --immutable: done
yarn test src/__tests__/native/repro-physical-border-light-dark.test.tsx: exit 0, 7 cases
.card { color-scheme: light dark; border: 2px solid light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderWidth":2,"borderStyle":"solid","borderColor":"#26e"}]}
{"s":[1,1],"d":[{"border":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderWidth":2,"borderStyle":"solid","borderColor":"#26e"}
rendered, dark scheme: {"borderWidth":2,"borderStyle":"solid","borderColor":"#26e","border":"#6af"}
dark scheme: borderColor "#26e", adds border, where borderColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-top: 2px solid light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderTopColor":"#26e","borderTopWidth":2}]}
{"s":[1,1],"d":[{"borderTop":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderTopColor":"#26e","borderTopWidth":2}
rendered, dark scheme: {"borderTopColor":"#26e","borderTopWidth":2,"borderTop":"#6af"}
dark scheme: borderTopColor "#26e", adds borderTop, where borderTopColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-right: 2px solid light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderRightColor":"#26e","borderRightWidth":2}]}
{"s":[1,1],"d":[{"borderRight":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderRightColor":"#26e","borderRightWidth":2}
rendered, dark scheme: {"borderRightColor":"#26e","borderRightWidth":2,"borderRight":"#6af"}
dark scheme: borderRightColor "#26e", adds borderRight, where borderRightColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-bottom: 2px solid light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderBottomColor":"#26e","borderBottomWidth":2}]}
{"s":[1,1],"d":[{"borderBottom":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderBottomColor":"#26e","borderBottomWidth":2}
rendered, dark scheme: {"borderBottomColor":"#26e","borderBottomWidth":2,"borderBottom":"#6af"}
dark scheme: borderBottomColor "#26e", adds borderBottom, where borderBottomColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-left: 2px solid light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderLeftColor":"#26e","borderLeftWidth":2}]}
{"s":[1,1],"d":[{"borderLeft":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderLeftColor":"#26e","borderLeftWidth":2}
rendered, dark scheme: {"borderLeftColor":"#26e","borderLeftWidth":2,"borderLeft":"#6af"}
dark scheme: borderLeftColor "#26e", adds borderLeft, where borderLeftColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-color: light-dark(#2266ee, #66aaff) red; }
compiled rules:
{"s":[1,1],"d":[{"borderTopColor":"#26e","borderBottomColor":"#26e","borderLeftColor":"#f00","borderRightColor":"#f00"}]}
{"s":[1,1],"d":[{"borderColor":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
{"s":[1,1],"d":[{"borderColor":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderTopColor":"#26e","borderBottomColor":"#26e","borderLeftColor":"#f00","borderRightColor":"#f00"}
rendered, dark scheme: {"borderTopColor":"#26e","borderBottomColor":"#26e","borderLeftColor":"#f00","borderRightColor":"#f00","borderColor":"#6af"}
dark scheme: borderTopColor "#26e", adds borderColor, where borderTopColor "#66aaff" alone is expected
.card { color-scheme: light dark; border-top-color: light-dark(#2266ee, #66aaff); }
compiled rules:
{"s":[1,1],"d":[{"borderTopColor":"#26e"}]}
{"s":[1,1],"d":[{"borderTopColor":"#6af"}],"m":[["=","prefers-color-scheme","dark"]]}
rendered, light scheme: {"borderTopColor":"#26e"}
rendered, dark scheme: {"borderTopColor":"#6af"}
dark scheme: borderTopColor "#6af", as expected
DEFECT: in the dark scheme 6 of 6 shorthands (border, border-top, border-right, border-bottom, border-left, border-color) keep #2266ee on their colour key, and their dark colour lands on border, borderTop, borderRight, borderBottom, borderLeft, borderColor instead, while border-top-color: light-dark() switches borderTopColor to #66aaff
Reproducible example repository
https://github.com/YevheniiKotyrlo/react-native-css/tree/repro/physical-border-light-dark
Activity