Skip to content

fix(v2): zh-CN never takes negative letter-spacing (TASK-055 class 1) - #1253

Merged
lilyshen0722 merged 2 commits into
mainfrom
t055/zh-no-negative-tracking
Aug 26, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
t055/zh-no-negative-tracking

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

TASK-055 — rule class 1 of 3: no negative tracking on CJK

Sam cleared these as repair under the UI freeze (TASK-055 row, 2026-08-26 07:07Z). Scoped to :lang(zh); English renders byte-for-byte the same.

Measured (real browser, .dev/task-055-zh-harness.html loading the real v2.css with zh-CN strings at 1200 / 390): .v2-chat__title 20px at -0.5px, .v2-pods__title 16px at -0.32px, .v2-inspector__now-title 15px at -0.15px, all rendering Chinese. 12 selectors in v2.css declare negative tracking; CJK glyphs have no side bearings so the value only crushes strokes.

Fix: one .v2-root:lang(zh) … block resets all 12 to letter-spacing: 0. html[lang] is set by frontend/src/i18n/index.ts.

Guard: v2-layout-invariants.test.ts scans v2.css for every negative letter-spacing selector and asserts each appears in the zh reset block — a new tracked title cannot ship without its reset.

Evidence screenshots (before): Sprint HQ uploads 1787696421491-793395730.png (1200) and 1787696423128-219977531.png (390). Sibling PRs: class 2 (CJK line-height 1.6 + 12px floor), class 3 (i18n literals).

🤖 Generated with Claude Code

…on the 12 tracked titles (TASK-055 class 1)

Measured in a real browser via .dev/task-055-zh-harness.html (real v2.css,
zh-CN strings, 1200 and 390): .v2-chat__title rendered Chinese at -0.5px,
.v2-pods__title at -0.32px, .v2-inspector__now-title at -0.15px. CJK glyphs
have no side bearings, so negative tracking only crushes strokes. One
:lang(zh) block resets all 12 selectors; English rendering is unchanged.
Invariant test asserts every negative-tracking selector in v2.css is in
the reset block, so a new tracked title cannot ship without its zh reset.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Gated at bbc542d9. One real miss, and it's in this PR's own defect class — plus a merge-order constraint that belongs on both this and #1254.

The fix is incomplete, and its guard cannot see the gap

v2.css sets negative tracking on a multi-line selector list:

.v2-feature__legacy .MuiTypography-h1,
.v2-feature__legacy .MuiTypography-h2,
.v2-feature__legacy .MuiTypography-h3,
.v2-feature__legacy .MuiTypography-h4,
.v2-feature__legacy .MuiTypography-h5,
.v2-feature__legacy .MuiTypography-h6 {
  color: var(--v2-text-primary);
  letter-spacing: -0.02em;
}

The reset block lists only .MuiTypography-h6. h1–h5 keep -0.02em on Chinese text. That surface is live — V2FeaturePage.tsx:342 renders .v2-feature__legacy.

The cause is the guard itself. The enumeration is

[...v2.matchAll(/\n([^\n{}]+) \{[^}]*letter-spacing:\s*-[^;]+;/g)]

[^\n{}]+ cannot cross a newline, so for a multi-line selector list it captures only the last line before the { — here, h6. The same regex that builds the required-reset list is the one that failed to see h1–h5, so the test passes with the defect present. That's the vacuity risk in any guard that derives both sides of its assertion from one source: it discriminates additions written in the shape it already parses, and is blind to the shape it doesn't.

I checked whether this is the only instance: scanning v2.css for rule blocks whose selector contains a comma and whose body has negative letter-spacing returns exactly one — this .v2-feature__legacy list. So the fix is adding five selectors, and widening the regex to split the full selector text on commas.

Merge-order constraint (also on #1254)

This PR and #1254 both append to v2.css and both append to v2-layout-invariants.test.ts, at the same locations. Each reads CLEAN against main individually, and they conflict with each other:

git merge-tree --write-tree pr-1253 pr-1254   → CONFLICT (both files)
merge #1253 to main, then #1254               → CONFLICT

CLEAN is pairwise-blind; whichever lands second needs a rebase. Worth knowing before the press rather than during it.

Verified

  • :lang(zh) genuinely matches — frontend/src/i18n/index.ts:12 sets document.documentElement.lang = 'zh-CN', and :lang(zh) matches the zh-CN subtag.
  • Specificity is sound: .v2-root:lang(zh) X is 0-3-0 against the base 0-2-0, and the block is appended last, so neither cascade order nor bundle order decides it.
  • CI Test & Coverage passes at this head.

Not verified

I did not render the harness. Every claim above is from the CSS text, the test source, and merge simulation — the measured px values in the comments are yours and I took them as given.

…ne selector lists

sprint-review's gate: the legacy feature-page heading rule is a six-line
selector list and the guard regex could not cross a newline, so it checked
h6 only and passed with h1–h5 still tracked negative under zh-CN. Guard now
captures the whole list and splits on commas; mutation-checked (dropping h3
from the reset fails exactly this test).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Re-gate at 0257b716. The miss is fixed and the guard now catches it.

.MuiTypography-h1 through -h5 are present in the :lang(zh) reset alongside the -h6 that was already there — 17 selectors, all reset.

The guard is genuinely discriminating now, which the previous one was not. It derives the negative-tracking selector set from v2.css itself, captures the whole multi-line selector list before splitting on commas, and asserts every member appears in the reset block. Mutations:

mutation guard
baseline pass, 17 selectors
drop .MuiTypography-h3 from the reset fail — missing: .v2-feature__legacy .MuiTypography-h3
drop .v2-chat__title from the reset fail — missing: .v2-chat__title
add a new negative-tracking title, unreset fail — missing: .v2-brand-new__title

It enumerates the protected items rather than their containers, so a new negative-tracking title added later fails closed instead of slipping past. That's the right inversion.

One residual, cosmetic. A negative-tracking rule written inside a @media block makes the regex capture the @media (min-width: 900px) line as the selector, so the guard fails with missing: @media (min-width: 900px). It still fails — closed, correctly — but the message names the wrong line and the next person will hunt for a selector that doesn't exist. Not worth another hardening pass; worth one sentence in the comment saying media-query rules report by their at-rule line.

How I ran it, and what that costs. react-scripts test will not run in a detached worktree here — the node_modules symlink doesn't resolve (MODULE_NOT_FOUND), same failure as the earlier TASK-055 attempts. So I executed the guard's assertion logic verbatim against this PR's real v2.css rather than through jest. That exercises the regex and the reset-block lookup, which is where the previous version failed; it does not exercise the jest harness around them. CI is 11/11 green at this head and covers that.

I also re-ran the first mutation with an explicit anchor assertion (includes(target) === true, count === 1, byte delta 57) — my first attempt used a mis-indented needle, did not apply, and reported a clean pass. A mutation that never applied is indistinguishable from one the guard ignores.

Still true and now the operative risk: #1253 and #1254 conflict with each other. Both are 11/11 green against main, and git merge-tree --write-tree pr-1253 pr-1254 still reports 2 conflicts at the current heads. #1253 × #1255 and #1254 × #1255 are clean. Whichever of the pair merges second needs a rebase before it is pressed — the green ticks are pairwise-blind and will not warn anyone.

@lilyshen0722
lilyshen0722 merged commit 0ee943d into main Aug 26, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the t055/zh-no-negative-tracking branch August 26, 2026 09:11
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.

1 participant