Skip to content

fix(webkit): [ENG-47001] close the token-check guardrail gap and canonicalize v4 syntax - #849

Open
isaque-bock-azion wants to merge 4 commits into
mainfrom
feat/ENG-47001-canonical-tailwind-v4-syntax
Open

fix(webkit): [ENG-47001] close the token-check guardrail gap and canonicalize v4 syntax#849
isaque-bock-azion wants to merge 4 commits into
mainfrom
feat/ENG-47001-canonical-tailwind-v4-syntax

Conversation

@isaque-bock-azion

@isaque-bock-azion isaque-bock-azion commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

ENG-47001 — canonicalize Tailwind v4 class syntax + close the token-check guardrail gap

Decision A (adopt the canonical syntax) — recorded in .claude/rules/styling.md and mirrored into the shipped cli-templates styling rule.

The load-bearing fix — guardrails (ships regardless of the codemod)

Six token-checks keyed on a literal [, so the canonical v4 paren spelling walked straight through the typography / motion / animation gates:

check evaded by
typography-raw-length text-(length:--text-…)
leading-raw leading-(--…)
tracking-raw tracking-(--…)
font-family-raw font-(family-name:--…)
animate-arbitrary animate-(--…)
motion-hardcoded duration-(--…)

Each now matches both spellings. Regression tests (packages/webkit/test/eslint-plugin/token-checks.test.mjs) pin every paren form named in the acceptance criteria and assert the widened guards stay silent on a plain canonical token (bg-(--primary)).

The sweep

Three families the real v4 compiler proves emit byte-identical CSS were rewritten across packages/webkit/src, apps/storybook, .specs, packages/webkit/docs, .claude/**, cli-templates, packages/theme:

family conversion count
A whole-value var prop-[var(--x)]prop-(--x) 2470
B typed value prop-[type:var(--x)]prop-(type:--x) 29
E numeric arbitrary z-[N]z-N 51

Two families are left bracketed — the paren form emits no CSS for them (silent style loss, no build/lint error):

  • C custom-property declarations — [--table-row-bg:var(--bg-surface)]
  • D expression values / var-with-fallback — w-[calc(var(--a)*2)], bg-[var(--x,var(--y))], gradients, box-shadows

The rewrite was done with a one-time codemod (not retained in the tree): it only converted a bracket whose content is exactly var(--token) (family A) or type:var(--token) with a letter-leading type (family B), so C and D could not match by construction — verified at apply-time (no C/D var-bracket changed) and permanently backstopped by the CI visual baselines, since any C/D breakage would change the rendered CSS.

Also

  • Standards/docs/scaffolder teach the paren form (DESIGN.md, COMPONENT_REQUIREMENTS.md, component-scaffold, the rule set, .specs).
  • apps/icons-gallery (Tailwind v3) untouched.

Notes for the reviewer / follow-ups

  • CI gates the rest. This branch was prepared without node_modules, so webkit:lint, type-check, storybook:build, the Vitest browser suite and visual baselines were not run locally — they run here. A/B/E compile byte-identically, so any baseline diff means the sweep broke something (the net for a C/D-style silent loss). The node guardrail suite is green: 10/10.
  • Root tailwindcss ^3.4.19 audit: no root Tailwind config and no root/sub-package consumer under pnpm's strict isolation (icons-gallery declares its own v3) → stale. Not removed here because regenerating pnpm-lock.yaml needs pnpm; recommend a follow-up that removes tailwindcss / @tailwindcss/typography / autoprefixer from the root and reinstalls.
  • packages/theme/dist/v4/globals.css is a generated artifact (do not edit banner); its one stale bracket-form comment regenerates on the next theme:build:tokens — the source (build-tokens.mjs) is already canonical.

…-check guardrails

typography-raw-length, leading-raw, tracking-raw, font-family-raw,
animate-arbitrary and motion-hardcoded keyed on a literal '[', so the
canonical v4 paren syntax (duration-(--x), animate-(--x), text-(length:--x),
font-(family-name:--x), leading-(--x), tracking-(--x)) walked straight through
the typography / motion / animation gates. Each now matches both spellings.
Regression tests pin both forms and assert the widened guards stay silent on a
plain canonical token (bg-(--primary)).
…tax repo-wide

Decision A: standardize on Tailwind v4's paren shorthand for design-token values
(bg-(--primary), text-(length:--text-body-md), z-1), so IntelliSense stops
flagging every styled line with suggestCanonicalClasses. The two spellings
compile to byte-identical CSS.

A codemod (scripts/codemods/canonicalize-tw-v4.mjs) rewrites the three safe
families across packages/webkit/src, apps/storybook, .specs, packages/webkit/docs,
.claude/**, cli-templates and packages/theme:
  A  prop-[var(--x)]      -> prop-(--x)        (2470)
  B  prop-[type:var(--x)] -> prop-(type:--x)   (29)
  E  z-[<int>]            -> z-<int>           (51)

It provably leaves two families bracketed, because the paren form emits no CSS
for them (silent style loss, no build or lint error):
  C  custom-property declarations  [--x:var(--y)]
  D  expression values / var-with-fallback  w-[calc(var(--a)*2)], bg-[var(--x,var(--y))]

canonicalize-tw-v4.test.mjs pins the A/B/E conversions and the C/D skips.
The decision is recorded in .claude/rules/styling.md and mirrored into the shipped
cli-templates styling rule; DESIGN.md and the scaffolder examples teach the paren
form. apps/icons-gallery (Tailwind v3) is untouched.
Comment thread scripts/codemods/canonicalize-tw-v4.mjs Fixed
The canonicalization sweep is applied and committed, so the one-shot codemod
(scripts/codemods/canonicalize-tw-v4.mjs) and its skip-proof test are no longer
needed — the permanent protection is the token-check guardrail tests plus the
CI visual baselines (which prove the A/B/E conversions are byte-identical).
Also removes the explanatory comments from the guardrail tests.
…weep

The canonicalization changed class-string lengths, so prettier re-wraps a few
:class attributes and the token-check test. Formatting only — no behavior change.
@CLAassistant

CLAassistant commented Aug 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants