fix(transforms): treat scale percentage values as unitless (#216)#389
Open
YevheniiKotyrlo wants to merge 2 commits into
Open
fix(transforms): treat scale percentage values as unitless (#216)#389YevheniiKotyrlo wants to merge 2 commits into
YevheniiKotyrlo wants to merge 2 commits into
Conversation
Tailwind v4 `scale-*` utilities crash React Native's transform validator
with `Transform with key of "scale" must be a number: {"scale":"75%"}`.
CSS `scale` accepts percentages (75% is a 0.75 factor) but RN's transform
only accepts unitless numbers, and the value reached the validator as the
string "75%" through two independent code paths -- both now fixed:
1. Compile-time (parseScaleValue): delegated unconditionally to parseLength,
which formats a lightningcss { type: "percentage", value: 0.75 } back
into the string "75%" (correct for layout props, wrong for transforms).
Short-circuit percentages to return the already-normalised decimal.
2. Runtime (scale() resolver): accepted string args as valid because its
type guard is `typeof x === "string" || "number"`. Tailwind v4 emits
`scale: var(--tw-scale-x) var(--tw-scale-y)` whose vars resolve to "75%"
at runtime, bypassing (1) entirely. Normalize "N%" -> N/100 before the
guards; rotate keeps "Ndeg" and translate keeps "N%" (only scale is
unitless).
Adds edge-case tests (identity, zero, negative, >100%, fractional, per-axis,
both var shapes, unitless-number regression) and corrects the vendor scale
tests that had encoded the buggy "N%" output.
Fixes nativewind#216
YevheniiKotyrlo
marked this pull request as ready for review
July 23, 2026 14:55
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.
Summary
Tailwind v4
scale-*utilities crash React Native's transform validator on native:CSS
scaleaccepts percentages (75%is a 0.75 factor), but RN's transform validator only accepts unitless numbers. The"75%"string reached the validator through two independent code paths, both fixed here:1. Compile-time (
parseScaleValue) delegated unconditionally toparseLength, which formats a lightningcss{ type: "percentage", value: 0.75 }back into the string"75%"— correct for layout props likewidth, wrong for transforms. Short-circuit percentages to return the already-normalised decimal.2. Runtime (
scale()resolver) accepted string args as valid because its guard istypeof x === "string" || typeof x === "number". This is the path Tailwind v4 actually hits —scale-75emitsscale: var(--tw-scale-x) var(--tw-scale-y)whose vars resolve to"75%"at runtime, bypassing (1). Normalize"N%"→N/100before the guards.rotatekeeps"Ndeg"andtranslatekeeps"N%"— onlyscaleis unitless.Fixes #216.
Reproduction (before this PR)
Crashes on first render with
Transform with key of "scale" must be a number: {"scale":"75%"}.Test plan
native/transform.test.tsx: single %, identity (100% → 1), zero (0% → 0), negative flip (-50% → -0.5), > 100% (150% → 1.5), fractional (12.5% → 0.125), per-axis (scale: 75% 50%), bothvar()shapes (the Tailwind emission, same and different per-axis), and a unitless-number regression guard (scale: 2stays2).scale — unparsedtest and the vendorTransforms - Scaletests (scale-0/scale-x-50/scale-y-50/scale-50) that had encoded the buggy"N%"output (they passed while the behaviour was broken).rotate/translatetests unchanged — onlyscalenormalizes%→ unitless.yarn test,yarn typecheck,eslint,prettierpass. (The three babel suites fail identically on cleanmainin this environment — missing--experimental-vm-modules— and are unrelated.)