Repository navigation
fix(ui-core): drop Typography's block wrapper for span and div - #32068
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| if (canUnwrap) { | ||
| return ( | ||
| <Component | ||
| {...otherProps} |
There was a problem hiding this comment.
not-prose disables typography styles
When an unwrapped span or div consumer supplies not-prose, the element receives both prose and not-prose, so the element-level prose selector no longer matches. Existing FieldCard names and descriptions therefore lose the wrapper’s 20px line-height, changing their visible vertical spacing.
✅ Playwright Results — workflow succeededValidated commit ✅ 738 passed · ❌ 0 failed · 🟡 1 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 34m 6s ⏱️ Max setup 6m 18s · max shard execution 17m 13s · max shard-job elapsed before upload 20m 43s · reporting 5s 🌐 177.61 requests/attempt · 1.70 app boots/UI scenario · 36.88% common-shard skew Optimization targets still in progress:
🟡 1 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
🚦 Removed from the merge queue —
|
🚦 Removed from the merge queue —
|
Typography wraps its content in a block-level `<div className="prose">` regardless of the `as` prop. Every inline usage therefore renders as a block element - text meant to sit mid-sentence takes its own line - and nesting one Typography inside another emits a `<div>` inside a `<span>`, which is invalid DOM and trips React's validateDOMNesting. `styles/typography.css` applies its real rules through a *descendant* selector (`.prose :not(...)`), and every rule in that block is gated on an element type: p, h1-h6, ol, ul, li, blockquote, a, code, pre, img, figure, table. For those the wrapper is load-bearing - moving `prose` onto the element itself would stop the rule matching and a `p` would silently lose its margins. `span` and `div` are targeted by no such rule. There the wrapper contributes only the element-level `.prose` layer - the `--tw-prose-*` vars plus `color`, `font-size` and `line-height`, all inherited properties - so setting `prose` directly on the element produces an identical computed style on the text while dropping the spurious block box. Render the element directly in that case. Ellipsis keeps the wrapper (it carries the truncation classes) and so does a non-default quote variant, which is also styled through a descendant selector. Deliberately a small allowlist: anything unlisted is unchanged. One test updated: ExploreQueryFilterChips asserted the *parent* carried `prose`, which encoded the wrapper as contract. Verified against main: 1222 suites / 14501 tests pass. The two remaining failures (CronUtils, ServiceConnectionUtils) fail identically on main without this change.
Two story names described the old model and are now wrong: "as prop — wraps children in inner element" and "as prop with className on inner element" both imply an outer wrapper that `span`/`div` no longer get. Documents the actual contract on the meta block - which elements keep the `.prose` wrapper and why - and adds two stories: - **DOM structure** — `span`/`div` render bare with `prose` on the element, while `p` and the other prose-targeted elements keep the wrapper so the descendant rules still match. Ellipsis keeps it too, to have somewhere to clip. - **Inline flow** — the reason the wrapper had to go: a block-level wrapper pushes each Typography onto its own line, breaking any sentence that mixes plain text with emphasised fragments. Storybook builds clean; eslint and prettier pass.
The two new stories had JSX lines over 80 columns. `ui-checkstyle` runs `prettier --write` on changed files and fails when the working tree comes back dirty, so this is a gate failure rather than a cosmetic nit. No behavioural change - line wrapping only.
… test Two CI failures from the rebase: - `href` / `target` / `rel` were lost resolving the props-interface conflict — main's side won and took them with it, leaving the `HTMLAttributeAnchorTarget` import orphaned. eslint caught it as an unused import; the real damage was the missing typing. Restored. - ContextCenterSubNavSections asserted on `.prose > span`, the shape from before the wrapper was dropped. A span now carries `prose` itself, so the heading is a direct child. The selector was coupled to exactly what this change alters. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Code Review ✅ Approved 1 closed / 1 findings🟡 Medium risk Refactors Typography to drop the block-level wrapper for ✅ 1 closed✅ Quality: Unused type import HTMLAttributeAnchorTarget
OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|



Typography wraps its element in a block-level
<div class="prose">. Forspananddivthat wrapper contributes nothing but a box — and costs correctness.Why the wrapper is load-bearing sometimes
styles/typography.cssapplies its real rules through a descendant selector (.prose :not(...)), and every rule inside is gated on an element type —p,h1-h6,ol,ul,li,blockquote,a,code,pre,img,figure, table elements. For those the wrapper has to stay: movingproseonto the element would stop the rule matching and, say, apwould silently lose its margins.spananddivare targeted by no such rule. For them the wrapper only contributes the element-level.proselayer —--tw-prose-*vars pluscolor,font-size,line-height, all inherited properties. Puttingprosedirectly on the element gives an identical computed style on the text, while dropping a block-level<div>that breaks inline flow and produces invalid<div>-inside-<span>nesting when Typography is nested.Decided from the element type, not a flag
#33021landed aninlineprop for the same problem while this PR was open. This replaces it, and removesinline.The reason is not just taste.
inlinewas unconditional, so passing it next toellipsisor a non-defaultquoteVariantsilently dropped a wrapper those genuinely need —ellipsiscarries its truncation classes there, and a quote variant styles content through.prose.prose-*-quote :not(...), another descendant selector. The call site has to know a rule it can't see.Deciding inside the component makes that unrepresentable:
UNWRAPPED_ELEMENTSis a deliberately small allowlist (span,div); anything not listed keeps the wrapper.Breaking change:
inlineis removed. It shipped 2 days ago in #33021 and its only consumers were 8 call sites infilter-select, all defaultas="span"— updated here, and they behave identically because the allowlist covers them. No other consumer in this repo or in Collate uses it.Also
Widens the anchor pass-through typing (
href/target/rel) for theas="a"shape used by antdTypography.Linkmigrations. These were already spread ontoComponentat runtime; this only makes the type match existing behaviour.Verification
tscclean;ui-checkstylea clean no-op.span/divrender unwrapped and carryprosethemselves, whilep/h1/a/blockquote/li,ellipsis, and a non-default quote variant all keep the wrapper.🤖 Generated with Claude Code
The PR is not yet safe to merge because existing
not-proseTypography consumers lose inherited prose line-height after being unwrapped.Findings
Summary
The PR conditionally removes Typography’s wrapper for
spananddiv, while retaining it for ellipsis, quote variants, and elements requiring descendant prose selectors.inlineprop and updates filter-select consumers.Reviews (8) · Last reviewed commit: "fix(ui-core): restore the anchor typing,..."