Repository navigation
fix: let a custom property set to initial override other declarations - #585
Merged
danstepanov merged 1 commit intoNov 23, 2026
Merged
Conversation
The compiler dropped `--x: initial` with a warning, so any other rule declaring the same variable won: Tailwind's `md:via-none`, `md:shadow-initial` and `md:inset-shadow-initial` kept the colour that `via-*`, `shadow-*` and `inset-shadow-*` set. The declaration now compiles to an `initial` marker. When it is an element's own winning value, var() skips the element's other rules, `*` and the parent, and takes the registered initial value or else its fallback (css-variables-1 §2.2, css-properties-values-api-1 §2). An ancestor's marker already resolves to nothing, which main treats as the guaranteed-invalid value. Co-authored-by: Yevhenii <evgeny.kotyrlo@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
danstepanov
force-pushed
the
fix/custom-property-initial
branch
from
November 23, 2026 21:06
33fbcc3 to
193c000
Compare
danstepanov
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The approach follows #391's
f9caff0(thanks @YevheniiKotyrlo). This is the part of it that fixes the Tailwind bug, written formainso it doesn't need the rest of #391.The bug
Tailwind v4 implements
via-noneand the*-initialutilities by setting a variable toinitial. The reader then takes itsvar()fallback:The compiler dropped
--x: initialwith a warning. So whenever another rule declared the same variable, that rule's value won. Used with a variant, these utilities did nothing:mdand widermainfrom-red-500 via-green-500 md:via-none to-blue-500shadow-md shadow-red-500 md:shadow-initialinset-shadow-sm inset-shadow-red-500 md:inset-shadow-initialOn its own (
shadow-md shadow-initial) the utility already worked, because the inliner turns a singleinitialinto the fallback. Every use of these utilities also printed a spuriousinitialvalue warning, which Metro builds show since #430.Hand-written CSS had the same bug:
.a { --x: red } .b { --x: initial }gaveredonclass="a b", and so did a child setting--x: initialunder a parent with--x: red.The fix
initialcompiles to aninitialmarker instead of being dropped.var()skips the element's other declarations,*and the parent's value. It takes the registered initial value if an@propertygives one, and otherwise its fallback (css-variables-1 §2.2, css-properties-values-api-1 §2). An ancestor's marker already resolves to nothing, whichmaintreats as the guaranteed-invalid value, so a child reading it takes its own fallback.The marker is an ordinary declaration, so the cascade decides the same way as any other value.
.a { --x: red !important } .b { --x: initial }still givesred, and--x: initial !importantbeats a later, normal--x: red, as in browsers (onmainthe second gavered).Regression status
Not a regression per-se relative to Tailwind 3 (Nativewind v4): that has no
via-noneor*-initialutilities.This is a bug that has always been in
react-native-css(i.e. Nativewind v5 pre-releases), and it reaches stock Tailwind utilities used with a variant (md:,dark:,hover:…) in Tailwind 4.Impact
*-initialandvia-nonevariant, var chains and arbitrary values) changes only the three rows above, each to the browser's result. Nothing fails React Native's validators.--x: initialnow overrides an earlier rule's value, a parent's value, and an earlier value from a rule inside@media. When--x: initialis itself!important, it also beats a later rule. As before, a later rule overridesinitial, and so does an!importantvalue thatinitialisn't.vendor/tailwind/initial-overrides.test.tsxruns the three utilities through real Tailwind at two widths. All 6 cases fail onmain: the 3 wide ones on the value, the 3 narrow ones on the spurious warning.native/variables.test.tsxadds 6 cases in two modes (variables inlined and kept). Onmain, 10 of the 12 fail; the two that pass check that a later rule still overridesinitial.initialvariable doesn't pay for it.Not in this PR
initialone, read through avar()with a fallback, still loses the fallback when variables are inlined (--y: var(--x)read asvar(--y, green)). fix(compiler): keep a var() substitution's meaning when inlining it #503 covers that.vars()or the variable provider (VariableContextProvider treats "unset", "inherit" and "initial" differently from CSS #573).text-shadow-initial,duration-initialandease-initialuse the same mechanism. They couldn't be observed in tests: React Native renders nothing for Tailwind's multi-layer text shadows, and transitions don't show in the jest style.