Repository navigation
fix: close Tailwind v4 parity gaps with @nativescript/core 9.x - #227
Conversation
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).
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
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.
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.
|
Thanks @aleclarson, great work on this! I pushed two commits on top after running the plugin through the real build chain (preset-env → 3a33897: fixes
eabf287: right-to-left Verified: 15/15 |
|
Thank you again for the contribution @aleclarson it's released in 4.1.0 https://github.com/NativeScript/tailwind/releases/tag/4.1.0 |
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/coreCSS registry and media query parser.Changes
1.
supportedPropertiesrefreshed against core'scssNameregistryAdds
gap,row-gap,column-gap(everygap-*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,visibilitygainshidden/collapsed,corner-shape: squircle|round).2.
visibility: hidden → collapserewrite removedCoreTypes.Visibility.isValidacceptshidden(core-types/index.ts), andvisibilityPropertyonly setsisCollapsedforcollapse. The rewrite made.invisibleremove elements from layout on native while the web keeps layout space — same class, different layout.hiddennow passes through.3.
@mediarewritten instead of deletedCore 8.8+ evaluates
width/height/device-width/device-height/orientation/prefers-color-schemewithmin-/max-modifiers (css-mediaquery/index.ts) — but only in colon syntax; Tailwind's range syntax(width >= 40rem)failsRE_MQ_EXPRESSIONand throws. NewrewriteMediaPrelude:(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/emin feature values → ×16 dips (Length.parsetreats bare numbers as dips)hover,prefers-reduced-motion,resolution, …) drop individually; the rule dies only when no comma-separated query survivesRestores
sm:–2xl:, media-flavordark:,portrait:/landscape:, and arbitrary[@media(...)]variants.4.
translate:/scale:unrolled onto core per-axis propertiesv4 emits
translate: var(--tw-translate-x) var(--tw-translate-y)andscale: …shorthand declarations — properties that don't exist in core. They're now rewritten totranslateX/translateY/scaleX/scaleY(all in core's registry), withvar()fallbacks (0for translate,1for scale) for the companion axis that's only initialized via@propertyon the web.5. Logical properties → physical sides
v4 emits
margin-inline,margin-inline-start/end,padding-inline,padding-block,border-inline-start-width, etc. forpx-*/py-*/mx-*/my-*/ps-*/pe-*/ms-*/me-*,space-*,divide-*, andborder-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)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-*,truncateall emit parseable, correctly-scoped output.Remaining known divergences (documented, not fixed)
:is()(needs the is-pseudo-class plugin step),@layer/@supportsflattening (cascade weight differs until core implements layers),@propertyremoval (--tw-*inherit differently),space/divide *-reversevariants,emtreated asrem,hover:/focus-within:/currentColor/vh/vw(genuinely unsupported by core).