Skip to content

fix: close Tailwind v4 parity gaps with @nativescript/core 9.x - #227

Merged
NathanWalker merged 8 commits into
NativeScript:mainfrom
aleclarson:fix/tw-parity-gaps
Oct 6, 2026
Merged

NathanWalker merged 8 commits into
NativeScript:mainfrom
aleclarson:fix/tw-parity-gaps

Conversation

@aleclarson

Copy link
Copy Markdown
Contributor

Closes #226.

Several rewrites and a stale property allowlist made identical Tailwind classes behave differently — or silently die — on native versus web. This PR fixes the ones that are fixable without new core capabilities; everything verified against the packages/core CSS registry and media query parser.

Changes

1. supportedProperties refreshed against core's cssName registry

Adds gap, row-gap, column-gap (every gap-* utility was stripped), white-space, text-overflow, max-width/max-height (max-w-*/max-h-*), perspective, direction, scaleX/scaleY/translateX/translateY, corner-shape, text-stroke, max-lines, and the NS-specific props (selected-*, separator-color, icon-font-family, android-content-inset*, status-bar-style, flex-flow, flex-wrap-before, android-status-bar-background). Value lists use core's validators (white-space: normal|nowrap|wrap, text-overflow: clip|ellipsis, direction: ltr|rtl, visibility gains hidden/collapsed, corner-shape: squircle|round).

2. visibility: hidden → collapse rewrite removed

CoreTypes.Visibility.isValid accepts hidden (core-types/index.ts), and visibilityProperty only sets isCollapsed for collapse. The rewrite made .invisible remove elements from layout on native while the web keeps layout space — same class, different layout. hidden now passes through.

3. @media rewritten instead of deleted

Core 8.8+ evaluates width/height/device-width/device-height/orientation/prefers-color-scheme with min-/max- modifiers (css-mediaquery/index.ts) — but only in colon syntax; Tailwind's range syntax (width >= 40rem) fails RE_MQ_EXPRESSION and throws. New rewriteMediaPrelude:

  • (width >= X) → (min-width: X), (width < X) → (max-width: X), value-first and double-sided ranges handled (inclusive min/max approximates exclusive </> — noted in code)
  • rem/em in feature values → ×16 dips (Length.parse treats bare numbers as dips)
  • Queries using features core can't evaluate (hover, prefers-reduced-motion, resolution, …) drop individually; the rule dies only when no comma-separated query survives

Restores sm:–2xl:, media-flavor dark:, portrait:/landscape:, and arbitrary [@media(...)] variants.

4. translate:/scale: unrolled onto core per-axis properties

v4 emits translate: var(--tw-translate-x) var(--tw-translate-y) and scale: … shorthand declarations — properties that don't exist in core. They're now rewritten to translateX/translateY/scaleX/scaleY (all in core's registry), with var() fallbacks (0 for translate, 1 for scale) for the companion axis that's only initialized via @property on the web.

5. Logical properties → physical sides

v4 emits margin-inline, margin-inline-start/end, padding-inline, padding-block, border-inline-start-width, etc. for px-*/py-*/mx-*/my-*/ps-*/pe-*/ms-*/me-*, space-*, divide-*, and border-x/y — none of which core parses, so those utility families silently died. Now rewritten to left/right/top/bottom (LTR reading; RTL apps would need a per-direction override — noted in code).

6. :where() expansion fixed for comma alternatives

.dark\:x:where(.ns-dark, .ns-dark *) used to splice raw text, producing .dark\:x.ns-dark, .ns-dark * — the second selector matched every descendant of .ns-dark, applying the variant's declarations to the whole tree. Alternatives now expand per-selector: .dark\:x.ns-dark, .ns-dark .dark\:x. Handles plain compounds (abbr:where([title])), ancestor contexts (.ns-dark *), and wrapped complex selectors (:where(.space-y > :not(:last-child))).

Test plan

  • test/parity.test.mjs — node --test, 7 cases covering each change (runs without tailwindcss; feeds authored CSS shaped like v4 output)
  • Verified end-to-end with tailwindcss@4.3.3 + @tailwindcss/postcss: sm:–lg: breakpoints, portrait:, @custom-variant dark, gap-*, space-x-*, divide-x-*, px-*/py-*, translate-x-*, scale-*, invisible, whitespace-*, max-w-*, truncate all emit parseable, correctly-scoped output.

Remaining known divergences (documented, not fixed)

:is() (needs the is-pseudo-class plugin step), @layer/@supports flattening (cascade weight differs until core implements layers), @property removal (--tw-* inherit differently), space/divide *-reverse variants, em treated as rem, hover:/focus-within:/currentColor/vh/vw (genuinely unsupported by core).

Fixes NativeScript#226 — several rewrites and a stale allowlist
made identical classes behave differently or silently die on native:

- supportedProperties refreshed against core's cssName registry:
  gap/row-gap/column-gap, white-space, text-overflow, max-width/height,
  perspective, direction, scaleX/scaleY/translateX/translateY,
  corner-shape, text-stroke, max-lines, and NS-specific props.
- visibility:hidden no longer rewritten to collapse — core accepts
  hidden (keeps layout space); the rewrite made .invisible remove
  elements from layout, unlike the web.
- @media is no longer deleted wholesale: range syntax
  (width >= 40rem) is rewritten to core-parseable colon form
  (min-width: 640) with rem/em converted to dips, and only queries
  using features core can't evaluate are dropped — restoring
  sm:-2xl: breakpoints, media dark:, and portrait/landscape.
- translate:/scale: shorthand declarations unroll onto core's
  per-axis translateX/translateY/scaleX/scaleY properties, with
  var() fallbacks for the unset companion axis (0 / 1).
- CSS logical properties (margin-inline, padding-block,
  border-inline-start-width, ...) rewrite to physical sides —
  px-*/py-*/mx-*/my-*/space-*/divide-* previously dropped silently.
- :where() now expands comma alternatives per-selector instead of
  splicing raw text, fixing dark:/group variants whose second
  alternative matched every descendant of the theme root.

Adds test/parity.test.mjs covering each change (node --test).
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 92c0ba0f-21a9-42fa-866d-97522d168b13

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

aleclarson added a commit to octane-xplat/octane-xplat that referenced this pull request Sep 25, 2026
NativeScript/tailwind#227 (our fork, fix/tw-parity-gaps) implements the
parity fixes from #226 — allowlist refresh, hidden pass-through, @media
range→colon rewrite, translate/scale and logical-property rewrites,
:where expansion.
aleclarson and others added 7 commits September 25, 2026 15:44
The previous unroll emitted translateX/scaleX/scaleY carrying
var(--tw-translate-x, 0) — on device it evaluates to unset:
element-scoped var() resolves to 'calc(var(--spacing) * 4)' (a nested
var() inside calc, which evaluateCssExpressions can't unwind), so the
winning declaration fails and the property falls back to its default
rather than the earlier static candidates.

Instead, rename the utility's own --tw-translate-x/--tw-translate-y/
--tw-scale-x/--tw-scale-y value declarations onto core's per-axis
properties and drop the var()-arg shorthand — the values are concrete
and evaluate cleanly. Scale percents normalize to factors (95% -> 0.95).
Literal shorthand args still unroll; single-arg scale hits both axes.
preset-env clones var()-carrying declarations into statically-
substituted versions (e.g. calc(4 * 4) for calc(var(--spacing) * 4)).
The var() original still resolves badly on device — var(--spacing)
expands to '.25rem' inside calc, which the core evaluator rejects ->
unset -> default. When a var-free sibling exists, drop ours so the
static value wins.
The \x00..\x1f sentinel in source wrote real NUL bytes into the file,
which made git classify it as binary. Plain ASCII sentinel is equally
collision-proof against real query text.
On-device verification showed stylesheet decls for translateX/scaleX/
scaleY never apply (CssAnimationProperty cssNames exist but the
stylesheet path doesn't reach them); only the transform: shorthand
reaches the engine via transformConverter. It requires literal numbers
(parseFloat inside translateX()/scaleX()), so calc()/var() args are
resolved statically: calc(var(--spacing) * N) against the stylesheet's
--spacing value (default .25rem -> 4 dips), percents to factors, rem
to dips.

All transform pieces in a rule merge into one transform: decl —
the shorthand resets every axis, so two decls would be last-wins.
Composition across utility rules on one element stays last-wins:
a core cascade limitation postcss can't merge away.
Emit a shared transform: decl reading all four --tw-* vars with
identity fallbacks. Whichever utility rule wins the cascade still
resolves every applied var through core's var() substitution, so
transform utilities compose like they do on the web. --tw-* decl
values are rewritten to literal numbers (--spacing*N, %->factor,
rem->dips) because core doesn't resolve nested var()/calc().
- rem conversion accepted one leading digit, so preset-env's
  `(max-width: 39.999rem)` became 3159.984 dips; multi-digit values now convert
- percent translates are dropped (core ignores `%` in transforms), and
  `calc(100% * -1)` scale args resolve, so -scale-x-100 mirrors
- transform: is only emitted for rules with a translate:/scale: shorthand,
  not the `*` var reset; translate/scale none map to identity
- `* + *` selects all-but-first, so space/divide gaps move to the start side
- `not` media queries are dropped, since core cannot parse them
- max-width/max-height none map to auto
ps-*/pe-*/ms-*/me-* and border-s/e keep their LTR physical rule, followed by
a `:where(.ns-rtl)` override that moves the value to the opposite side and
unsets the LTR one. :where() keeps the override's specificity equal to the
original so later physical utilities (pl-*, pr-*) still win; without core's
.ns-rtl root class (core 9.0+) the override never matches.
@NathanWalker

Copy link
Copy Markdown
Contributor

Thanks @aleclarson, great work on this! I pushed two commits on top after running the plugin through the real build chain (preset-env → @tailwindcss/postcss → this plugin, Tailwind 4.3.3):

3a33897: fixes

  • max-* breakpoints: preset-env emits (max-width: 39.999rem), and the rem regex only took one leading digit, which gave 3159.984. Multi-digit values now convert (639.984, and 12.5rem → 200).
  • Percent translates (translate-x-1/2, -full) are dropped, since core ignores % in transforms. calc(100% * -1) scale args now resolve, so -scale-x-100 mirrors.
  • transform: is only emitted for rules with a translate:/scale: shorthand, so the * var-reset rule no longer gets one. translate: none/scale: none map to identity.
  • * + * selects all-but-first, so space/divide gaps move to the start side to stay between items.
  • not (...) media queries are dropped (core can't parse them). max-width/max-height: none → auto.

eabf287: right-to-left
ps-*/pe-*/ms-*/me-* and border-s/e keep their LTR rule, followed by a :where(.ns-rtl) .x override that flips the side. :where() keeps the specificity equal, so later pl-*/pr-* still win, as on the web. The override only matches under core 9.0+'s .ns-rtl root class; otherwise output is unchanged.

Verified: 15/15 parity.test.mjs, and the generated CSS (14.5k classes) parses with no bad selectors or media queries in npm css, core's rework parser, and css-tree.

@NathanWalker
NathanWalker merged commit ea2c350 into NativeScript:main Oct 6, 2026
1 check passed
@NathanWalker

Copy link
Copy Markdown
Contributor

Thank you again for the contribution @aleclarson it's released in 4.1.0 https://github.com/NativeScript/tailwind/releases/tag/4.1.0

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.

Tailwind v4 parity gaps: stale allowlist strips core-supported props, all @media dropped, hidden→collapse rewrite is wrong on modern core

2 participants