Skip to content

fix(Text, Heading): preserve words in single-line truncation - #11830

Open
bezabyte wants to merge 2 commits into
meta:mainfrom
bezabyte:codex/issue-11790-word-break
Open

bezabyte wants to merge 2 commits into
meta:mainfrom
bezabyte:codex/issue-11790-word-break

Conversation

@bezabyte

Copy link
Copy Markdown
Contributor

What changed

  • Changed the default wordBreak behavior for Text and Heading truncation to break-word for both maxLines={1} and multi-line truncation.
  • Kept the explicit wordBreak="break-all" escape hatch unchanged for callers that intentionally split inside words.
  • Added unit coverage for the normal single-line clamp and for callers that restore wrapping with whiteSpace: 'normal'.
  • Extended the existing Chromium reflow contract to verify the computed normal / break-word pair.
  • Updated the component API descriptors and Text/Heading specs, with a patch changeset.

Why

The previous single-line default was word-break: break-all. It was invisible while the component's own white-space: nowrap was active, but an application that restored wrapping could split ordinary words at arbitrary letters. The default now follows the same word-preserving behavior already used by multi-line truncation.

Before / after

Before, the default computed styles for a single-line clamp were:

word-break: break-all
overflow-wrap: normal

After, they are:

word-break: normal
overflow-wrap: break-word

The default white-space: nowrap and ellipsis are unchanged. When a caller sets whiteSpace: 'normal', words now remain intact instead of being split by the component's default.

Verification

  • pnpm exec vitest run packages/core/src/Text/Text.test.tsx packages/core/src/Heading/Heading.test.tsx — 90 tests passed.
  • pnpm -F @astryxdesign/core typecheck — passed.
  • pnpm check:repo — passed; the existing temporary-status messages are warnings only.
  • Chromium Text reflow contract — 4 tests passed after rebuilding Storybook.
  • Targeted ESLint and Prettier checks — passed.

The browser contract writes local evidence screenshots under test-results/text-reflow-evidence/; the default nowrap state is visually unchanged, so no misleading screenshot is embedded here.

Closes #11790

@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 16, 2026 4:41am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 15, 2026
@astracat-bot

astracat-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 21, 2026, 4:59 AM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:spec-owner-review Current knowledge records await owner approval labels Nov 15, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request is waiting on an engineering owner's decision, and it needs three fixes either way.

component:Text FR4 and component:Heading FR4 currently say a truncated single line defaults to wordBreak="break-all", and this change rewrites both to break-word. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner), and approval waits on it.

Required fixes:

  • Heading's Chinese and dense prop docs (Heading.doc.mjs lines 209 and 287), the TextWordBreak block template (line 28) and the Text "Word Break Variants" story (Text.stories.tsx line 423) still say break-all is the single-line default, so astryx component Heading --dense and --zh now describe the opposite of what ships.
  • The changeset should be tagged [feat] and name the old and new default plus the wordBreak="break-all" opt-in, as the release rules ask for an intentional typography default change.
  • The title's scope fix(Text) leaves out Heading, whose wordBreak default also changes, so retitle it fix(Text, Heading): … or list both components under a ## Scope heading.

The behavior itself checks out: the new tests fail on main and pass here, and the default one-line ellipsis renders identically.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim: the default wordBreak becomes break-word for single-line and multi-line truncation in Text and Heading. Verified: Text.tsx:260, Heading.tsx:249, Chromium computed styles.
  • Claim: an explicit wordBreak="break-all" still splits inside words. Verified: text.stylex.ts:283-285, Chromium computed styles.
  • Claim: unit tests cover the default single-line clamp and restored wrapping. Verified: Text.test.tsx:253-272, Heading.test.tsx:325-348; they fail on main and pass here.
  • Claim: the Chromium reflow contract checks the computed normal / break-word pair. Verified by reading TextReflow.a11y.chromium.spec.ts:114-126; not run here, the same values were measured in Chromium.
  • Claim: the component API descriptors and both specs are updated, with a patch changeset. Partly false: the English descriptors and both FR4 rows are updated; Heading's Chinese and dense descriptors are not.
  • Claim: the old default was invisible under nowrap, and the default ellipsis is unchanged. Verified: the Single Line Truncation story renders pixel-identical.
  • Claim: computed styles move from break-all / normal to normal / break-word. Verified in Chromium.
  • Claim: the two test files pass (90 tests), Core typecheck passes, targeted ESLint and Prettier pass. Verified. The repository check and the Chromium contract run were not repeated.
  • Changeset claim: single-line Text and Heading keep words whole when wrapping is restored. Verified in Chromium; the tag and wording fall short as noted above.
  • .changeset/single-line-word-break.md: finding (tag and wording).
  • docs/specs/components/Heading/Heading.spec.md: FR4 rewrite awaits the owner decision.
  • docs/specs/components/Text/Text.spec.md: FR4 rewrite awaits the owner decision.
  • packages/core/src/Heading/Heading.test.tsx: clear.
  • packages/core/src/Heading/Heading.tsx: finding (outside the title scope); default awaits the owner decision.
  • packages/core/src/Text/Heading.doc.mjs: finding (Chinese and dense entries still give the old default).
  • packages/core/src/Text/Text.doc.mjs: clear.
  • packages/core/src/Text/Text.test.tsx: clear.
  • packages/core/src/Text/Text.tsx: default awaits the owner decision.
  • packages/core/src/Text/__tests__/TextReflow.a11y.chromium.spec.ts: clear.

Automated review (maintainer link)

Comment thread .changeset/single-line-word-break.md Resolved
Comment thread packages/core/src/Text/Heading.doc.mjs Resolved
Comment thread packages/core/src/Heading/Heading.tsx Resolved
@bezabyte bezabyte changed the title fix(Text): preserve words in single-line truncation fix(Text, Heading): preserve words in single-line truncation Nov 16, 2026
@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up in : updated Heading dense/Chinese descriptors, the TextWordBreak template, and the Word Break Variants story; changed the changeset to with the old/new default and explicit opt-in. The engineering-owner decision on the FR4 record remains intentionally open.

@bezabyte

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up in ea12305: updated Heading dense/Chinese descriptors, the TextWordBreak template, and the Word Break Variants story; changed the changeset to [feat] with the old/new default and explicit wordBreak="break-all" opt-in. The engineering-owner decision on the FR4 record remains intentionally open.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request is waiting on an engineering owner's spec decision; the fixes from the earlier review are all in.

component:Text FR4 and component:Heading FR4 currently say a truncated single line defaults to wordBreak="break-all", and this change intentionally rewrites both to break-word. An engineering owner settles it by commenting /approve-spec <full head SHA> on this pull request to approve the new FR4 text (the author may do so if they are an engineering owner); if the owner keeps break-all for maxLines={1}, the one-line default and both FR4 rows go back.

Otherwise the change checks out: the new tests fail on main and pass here, and the default one-line ellipsis renders identically.

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Claim: Text and Heading default wordBreak to break-word for single-line and multi-line truncation. Verified: Text.tsx:260, Heading.tsx:249, Chromium computed styles.
  • Claim: an explicit wordBreak="break-all" still splits inside words. Verified: text.stylex.ts:283-285, Chromium shows the same split lines on main and here.
  • Claim: unit tests cover the default single-line clamp and restored wrapping. Verified: Text.test.tsx:253-272, Heading.test.tsx:325-348; they fail on main and pass here.
  • Claim: the Chromium reflow contract checks the computed normal / break-word pair. Verified by reading TextReflow.a11y.chromium.spec.ts:114-126; not run here, and the same values were measured in Chromium.
  • Claim: the component API descriptors and both specs are updated, with a patch changeset. Verified: Text.doc.mjs:121, Heading.doc.mjs:85, :209, :287, both FR4 rows, patch bump.
  • Claim: the old single-line default was invisible under nowrap, and nowrap and the ellipsis are unchanged. Verified: the Text and Heading single-line truncation stories render pixel-identical.
  • Claim: computed styles move from break-all / normal to normal / break-word, and words stay whole once white-space: normal is restored. Verified in Chromium.
  • Claim: the two test files pass (90 tests), Core typecheck passes, targeted ESLint and Prettier pass. Verified. The repository check and the Chromium contract run were not repeated.
  • Changeset claim: the single-line default changes from break-all to break-word, with wordBreak="break-all" as the opt-in, released as a patch [feat]. Verified against the code; the release-note rules for a typography default are met.
  • Author follow-up claim: Heading's dense and Chinese descriptors, the block template, the story and the changeset were updated. Verified.
  • .changeset/single-line-word-break.md: clear.
  • apps/storybook/stories/Text.stories.tsx: clear.
  • docs/specs/components/Heading/Heading.spec.md: FR4 rewrite awaits the owner decision.
  • docs/specs/components/Text/Text.spec.md: FR4 rewrite awaits the owner decision.
  • packages/cli/assets/templates/blocks/components/Text/TextWordBreak.tsx: non-blocking note (template rubric C, unchanged from main).
  • packages/core/src/Heading/Heading.test.tsx: clear.
  • packages/core/src/Heading/Heading.tsx: default awaits the owner decision.
  • packages/core/src/Text/Heading.doc.mjs: clear.
  • packages/core/src/Text/Text.doc.mjs: clear.
  • packages/core/src/Text/Text.test.tsx: clear.
  • packages/core/src/Text/Text.tsx: default awaits the owner decision.
  • packages/core/src/Text/__tests__/TextReflow.a11y.chromium.spec.ts: clear.

Automated review (maintainer link)

@duytbp

duytbp commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Thanks for this! I ran an independent check on head ea12305:

Verdict: approve. No defect found. In real browsers, the one-line ellipsis renders pixel-identical with the new default in every layout I tried. Once a rule lets the line wrap again, the old default split words and the new one splits none. This is evidence for the pending FR4 decision: keeping break-all for maxLines={1} buys no visual difference while the line stays nowrap, and it splits words as soon as the line wraps.

What I ran

Scratch clone, Node 24.22.1, pnpm install --frozen-lockfile.

  1. vitest run --project ui packages/core/src/Text packages/core/src/Heading: 8 files, 365 tests, all pass on the head.

  2. Leftover defaults: git grep break-all on the head finds no maxLines-based break-all default anywhere else in packages/core (CodeBlock's break-all is its own), and no remaining "break-all for one line" claim in specs, docs (Text.doc.mjs, Heading.doc.mjs, both locales), stories or CLI templates.

  3. Rendering, plain HTML with the two rule sets the atomic classes produce, in Playwright with Chromium 1248 and Firefox 1555 at 16px sans-serif:

    • before: overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:block; word-break:break-all
    • after: the same with word-break:normal; overflow-wrap:break-word

    Seven strings: Latin words, a long URL, a German compound, Chinese, Thai (no spaces), Arabic (RTL), and emoji ZWJ sequences mixed with words. Six containers: a 180px block, a flex child with min-width:0, an auto-layout table cell, a grid-template-columns:auto 1fr cell, a shrink-to-fit inline-block, and a parent with overflow-wrap:anywhere, which stands in for the Banner and Toast containers. For each pair I compared a page screenshot and the element's box.

Browser nowrap (the default) Line wrapping restored (white-space:normal, Latin string, 180px)
Chromium 42 of 42 identical (screenshot and box) words split: before 1, after 0
Firefox 42 of 42 identical* words split: before 2, after 0

* One Firefox pair (Chinese in the plain block) differed on the first run with the same box. Four repeated shots showed the old rule's own rendering varying between runs (a font-fallback load), and the last old and new shots matched byte for byte.

The anywhere parent case matters because the old break-all class set no overflow-wrap, so a one-line clamp inherited anywhere inside those containers. It now gets break-word. Under nowrap that changes nothing, as the table shows (min-content is the whole line either way).

Notes (non-blocking)

  • I didn't run TextReflow.a11y.chromium.spec.ts, which needs a Storybook build. The plain-HTML check above covers the same computed values in a real engine.
  • An app that wants long unbroken tokens to wrap inside a narrow auto-sized column, after restoring wrapping, still needs its own overflow-wrap:anywhere, because break-word keeps min-content at the longest word. That matches maxLines above 1 and FR3, so it's consistent and not a gap in this PR.

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 21, 2026
@cixzhang
cixzhang marked this pull request as draft November 21, 2026 04:59
@cixzhang
cixzhang marked this pull request as ready for review November 21, 2026 05:00
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · ea12305

Storybook · Sandbox · built from this PR's head

Current run: Heavy CI deferred: runs when review passes and before merge. Lint, typecheck and any path-filtered checks ran on this push.


Generated by PR Enrichment workflow | View current CI run

@cixzhang cixzhang removed the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 21, 2026

This branch was successfully deployed

1 active deployment
Preview — ea12305a Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:spec-owner-review Current knowledge records await owner approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Text, Heading: maxLines={1} defaults to word-break: break-all, which splits words once the line wraps

4 participants