Skip to content

perf(EmptyState): look for a live-region ancestor before the visibility read - #13747

Merged
cixzhang merged 2 commits into
mainfrom
lane2/emptystate-live-ancestor-first
Nov 24, 2026
Merged

cixzhang merged 2 commits into
mainfrom
lane2/emptystate-live-ancestor-first

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

User impact

When an EmptyState appears inside an element that is already a live region (a role="status" or role="log" container, for example), the shared announcement hook first reads the element's visibility with checkVisibility(), which forces a style update, and only then finds the live region and decides to say nothing. Every such EmptyState pays a forced style update for no announcement. Announcements do not change.

Problem and solution fit

  • Why is there a forced style update? useAnnounceRenderedText checks visibility before it walks up to a live-region ancestor, although inside a live region it never announces.
  • Why does that harm the task? A forced style update during a commit adds main-thread work on a busy page, for example a results list that swaps to its empty state.
  • Why does it matter? architecture:react-component-runtime INV18 asks components to read layout as little as possible; a style read the component does not need is the same kind of work.

The fix moves the cheap ancestor walk before the visibility read, so the read happens only when an announcement can still happen.

Expected behavior and authority

  • EmptyState AR3 and spec:AST-086 FR4: inside a live container, the container speaks its content and EmptyState announces nothing.
  • architecture:react-component-runtime INV18: layout is read as little as possible.

Smallest restoration

  • hooks/useAnnounceRenderedText.ts: the [aria-hidden]/[hidden] ancestor check and the live-region ancestor walk (for owners that skip the first render, as EmptyState, Spinner and ChatComposer do) now run before checkVisibility(). The decisions are the same; only their order changes.
  • EmptyState.spec.md: AR3's rule text now says what its verification row already tested. Inside an element that is already a live region, EmptyState announces nothing, and that region speaks its content.

Evidence

  • Reproduction before the change: the new test case fails on the base: checkVisibility is called once for an EmptyState inside a role="status" container.
  • Result after the change: no visibility read inside the container, and nothing announced.
  • Representative unchanged path: outside a live container, the visibility read still happens and the message is announced once (new test). All existing EmptyState, Spinner, ChatComposer and announcement-hook tests pass.
  • Regression test: EmptyState.announce.test.tsx, "reads no visibility for an empty state inside a live container, and announces nothing".

Scope

Components: EmptyState, hooks (useAnnounceRenderedText)

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

R1 narration: none; the added sentence states what the component does.
R2 research: none.
R3 evidence: none changed.
R4 rejected alternatives: none.
R5 change references: none.
R6 open questions: none.
R7 project status: none.

Testing

  • vitest run --project ui packages/core/src/EmptyState packages/core/src/hooks/useAnnounceRenderedText.test.tsx packages/core/src/hooks/useAnnounceRenderedText.adopters.test.tsx packages/core/src/Spinner packages/core/src/Chat: 639 passed. The new live-container case fails on the base.
  • tsc --noEmit -p packages/core clean; ESLint clean; check:knowledge aligned; comment-provenance baseline and check:changesets pass.

Overlap checked: #13567 (a contributor fix in the same hook for rendering without a document; it changes the renderedWithPage initialiser, a different hunk from this PR's effect-order change, so either can merge first)

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

vercel Bot commented Nov 24, 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 24, 2026 7:43pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 24, 2026, 8:03 PM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 24, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 2ec6a50

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · ae383da

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
lab/TransferList 142.3 kB (+13 B) · 1.2 kB CSS (0) — — · — · —
charts/ChartTooltip 230.9 kB (+11 B) · 451 B CSS (0) — — · — · —
AlertDialog 136.5 kB (+10 B) · 16.3 kB CSS (0) — — · — · —
121 more components
Component Size LoC Visual · A11y · RTL
CommandPaletteInput 34.7 kB (+10 B) · 8.3 kB CSS (0) — — · — · —
ChatMessageList 29.1 kB (+9 B) · 7.8 kB CSS (0) — — · — · —
DropdownMenu 136.3 kB (+9 B) · 19.9 kB CSS (0) — — · — · —
Pagination 157.4 kB (+9 B) · 20.2 kB CSS (0) — — · — · —
ChatComposerInput 90.6 kB (+8 B) · 12.6 kB CSS (0) — — · — · —
ChatComposerTokenElement 90.6 kB (+8 B) · 12.6 kB CSS (0) — — · — · —
Spinner 25.7 kB (+8 B) · 6.9 kB CSS (0) — — · — · —
TableHeaderCell 110.8 kB (+8 B) · 20.1 kB CSS (0) — — · — · —
lab/VideoPlayer 239.9 kB (+8 B) · 2.1 kB CSS (0) — — · — · —
ChatToolCalls 33.6 kB (+7 B) · 9.2 kB CSS (0) — — · — · —
EmptyState · Storybook 7.2 kB (+7 B) · 510 B CSS (0) 146 (0) ✓ · ✓ · —
IconButton 69.7 kB (+7 B) · 11.2 kB CSS (0) — — · — · —
InputGroup 65.4 kB (+7 B) · 9.2 kB CSS (0) — — · — · —
TableCell 110.9 kB (+7 B) · 20.3 kB CSS (0) — — · — · —
TimeInput 184.3 kB (+7 B) · 17.9 kB CSS (0) — — · — · —
Avatar 48.3 kB (+6 B) · 6.3 kB CSS (0) — — · — · —
AvatarGroup 51.1 kB (+6 B) · 6.4 kB CSS (0) — — · — · —
BreadcrumbItem 106.0 kB (+6 B) · 14.1 kB CSS (0) — — · — · —
Button 69.6 kB (+6 B) · 11.2 kB CSS (0) — — · — · —
Carousel 80.2 kB (+6 B) · 12.2 kB CSS (0) — — · — · —
ChatLayoutScrollButton 70.2 kB (+6 B) · 11.4 kB CSS (0) — — · — · —
ChatSendButton 70.1 kB (+6 B) · 11.2 kB CSS (0) — — · — · —
CheckboxListItem 84.8 kB (+6 B) · 12.8 kB CSS (0) — — · — · —
DateTimeInput 236.3 kB (+6 B) · 20.7 kB CSS (0) — — · — · —
DrawerHeader 73.1 kB (+6 B) · 14.3 kB CSS (0) — — · — · —
DropdownMenuSubMenu 82.8 kB (+6 B) · 11.4 kB CSS (0) — — · — · —
Field 63.3 kB (+6 B) · 8.0 kB CSS (0) — — · — · —
FieldLabel 58.8 kB (+6 B) · 6.5 kB CSS (0) — — · — · —
InfoTip 53.4 kB (+6 B) · 6.0 kB CSS (0) — — · — · —
Markdown 213.8 kB (+6 B) · 23.6 kB CSS (0) — — · — · —
MultiSelector 112.2 kB (+6 B) · 19.0 kB CSS (0) — — · — · —
RadioListItem 81.1 kB (+6 B) · 11.5 kB CSS (0) — — · — · —
SegmentedControl 105.3 kB (+6 B) · 7.6 kB CSS (0) — — · — · —
Selector 124.5 kB (+6 B) · 19.8 kB CSS (0) — — · — · —
SideNav 118.0 kB (+6 B) · 12.6 kB CSS (0) — — · — · —
SideNavCollapseButton 70.5 kB (+6 B) · 11.3 kB CSS (0) — — · — · —
SideNavHeading 91.1 kB (+6 B) · 12.6 kB CSS (0) — — · — · —
StatusDot 36.1 kB (+6 B) · 6.0 kB CSS (0) — — · — · —
Stepper 71.4 kB (+6 B) · 11.3 kB CSS (0) — — · — · —
Switch 113.7 kB (+6 B) · 10.8 kB CSS (0) — — · — · —
TextArea 97.1 kB (+6 B) · 10.3 kB CSS (0) — — · — · —
Tooltip 34.4 kB (+6 B) · 5.1 kB CSS (0) — — · — · —
Typeahead 98.2 kB (+6 B) · 14.5 kB CSS (0) — — · — · —
lab/AudioPlayer 242.3 kB (+6 B) · 1.8 kB CSS (0) — — · — · —
lab/Comments 394.0 kB (+6 B) · 2.5 kB CSS (0) — — · — · —
lab/CommentThread 387.1 kB (+6 B) · 2.4 kB CSS (0) — — · — · —
lab/Schedule 121.4 kB (+6 B) · 3.9 kB CSS (0) — — · — · —
lab/TransferListSelector 154.5 kB (+6 B) · 1.4 kB CSS (0) — — · — · —
Banner 71.7 kB (+5 B) · 11.7 kB CSS (0) — — · — · —
ChatComposer 93.5 kB (+5 B) · 13.6 kB CSS (0) — — · — · —
ChatLayout 93.5 kB (+5 B) · 11.7 kB CSS (0) — — · — · —
CheckboxList 77.4 kB (+5 B) · 8.5 kB CSS (0) — — · — · —
CommandPalette 84.7 kB (+5 B) · 13.8 kB CSS (0) — — · — · —
ContextMenu 109.8 kB (+5 B) · 19.7 kB CSS (0) — — · — · —
DateInput 212.1 kB (+5 B) · 19.0 kB CSS (0) — — · — · —
DateRangeInput 109.2 kB (+5 B) · 14.3 kB CSS (0) — — · — · —
DialogHeader 72.9 kB (+5 B) · 12.9 kB CSS (0) — — · — · —
FileInput 79.8 kB (+5 B) · 12.9 kB CSS (0) — — · — · —
MoreMenu 136.6 kB (+5 B) · 19.9 kB CSS (0) — — · — · —
NumberInput 108.6 kB (+5 B) · 13.1 kB CSS (0) — — · — · —
PowerSearch 323.7 kB (+5 B) · 27.4 kB CSS (0) — — · — · —
RadioList 64.8 kB (+5 B) · 8.0 kB CSS (0) — — · — · —
SideNavItem 85.2 kB (+5 B) · 12.5 kB CSS (0) — — · — · —
TabMenu 87.4 kB (+5 B) · 12.5 kB CSS (0) — — · — · —
TextInput 103.6 kB (+5 B) · 12.9 kB CSS (0) — — · — · —
Thumbnail 74.2 kB (+5 B) · 12.8 kB CSS (0) — — · — · —
Toast 109.7 kB (+5 B) · 11.5 kB CSS (0) — — · — · —
ToggleButton 97.2 kB (+5 B) · 11.3 kB CSS (0) — — · — · —
TopNavMegaMenu 84.4 kB (+5 B) · 13.2 kB CSS (0) — — · — · —
lab/ChatReactionBar 132.8 kB (+5 B) · 1.1 kB CSS (0) — — · — · —
lab/CommentComposer 190.2 kB (+5 B) · 1.9 kB CSS (0) — — · — · —
lab/CommentPin 63.2 kB (+5 B) · 1.2 kB CSS (0) — — · — · —
lab/MediaPlayButton 232.5 kB (+5 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaSeekButton 232.5 kB (+5 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaTime 232.5 kB (+5 B) · 1.5 kB CSS (0) — — · — · —
lab/SelectableCardGroup 73.7 kB (+5 B) · 162 B CSS (0) — — · — · —
richtext/RichTextEditor 313.2 kB (+5 B) · 2.7 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 319.7 kB (+5 B) · 454 B CSS (0) — — · — · —
AppShell 93.9 kB (+4 B) · 15.0 kB CSS (0) — — · — · —
AvatarGroupOverflow 54.4 kB (+4 B) · 6.3 kB CSS (0) — — · — · —
BaseTypeahead 86.6 kB (+4 B) · 12.2 kB CSS (0) — — · — · —
Calendar 80.9 kB (+4 B) · 11.8 kB CSS (0) — — · — · —
ChatDictationButton 70.2 kB (+4 B) · 11.3 kB CSS (0) — — · — · —
CheckboxInput 73.4 kB (+4 B) · 10.9 kB CSS (0) — — · — · —
CodeBlock 85.8 kB (+4 B) · 12.9 kB CSS (0) — — · — · —
Lightbox 153.6 kB (+4 B) · 12.4 kB CSS (0) — — · — · —
Link 59.7 kB (+4 B) · 7.8 kB CSS (0) — — · — · —
ListItem 84.0 kB (+4 B) · 12.8 kB CSS (0) — — · — · —
MobileNav 82.1 kB (+4 B) · 11.8 kB CSS (0) — — · — · —
Popover 108.1 kB (+4 B) · 15.7 kB CSS (0) — — · — · —
Slider 119.0 kB (+4 B) · 9.6 kB CSS (0) — — · — · —
Table 129.2 kB (+4 B) · 21.3 kB CSS (0) — — · — · —
TableSelectionToolbar 80.3 kB (+4 B) · 14.6 kB CSS (0) — — · — · —
TopNav 73.3 kB (+4 B) · 12.1 kB CSS (0) — — · — · —
TopNavHeading 90.8 kB (+4 B) · 12.6 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 131.6 kB (+4 B) · 773 B CSS (0) — — · — · —
lab/DialogHeroHeader 94.4 kB (+4 B) · 372 B CSS (0) — — · — · —
lab/DiffViewer 98.8 kB (+4 B) · 2.3 kB CSS (0) — — · — · —
lab/ListInput 99.5 kB (+4 B) · 922 B CSS (0) — — · — · —
lab/MediaCaptionsButton 232.5 kB (+4 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaFullscreenButton 232.5 kB (+4 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaPlaybackRate 232.5 kB (+4 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaTimeSlider 232.5 kB (+4 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaVolume 232.5 kB (+4 B) · 1.5 kB CSS (0) — — · — · —
richtext/RichTextView 289.9 kB (+4 B) · 2.4 kB CSS (0) — — · — · —
charts/Chart 254.4 kB (+3 B) · 516 B CSS (0) — — · — · —
TopNavMenu 90.2 kB (+3 B) · 12.6 kB CSS (0) — — · — · —
lab/TabBarMoreList 107.4 kB (+3 B) · 1.8 kB CSS (0) — — · — · —
lab/TourStep 99.2 kB (+3 B) · 691 B CSS (0) — — · — · —
ComplexSelector 86.5 kB (+2 B) · 13.3 kB CSS (0) — — · — · —
NavHeadingMenuItem 19.9 kB (+2 B) · 7.0 kB CSS (0) — — · — · —
MobileNavToggle 71.5 kB (+1 B) · 11.8 kB CSS (0) — — · — · —
Timer 14.5 kB (+1 B) · 6.7 kB CSS (0) — — · — · —
ProgressBar 12.6 kB (0) · 7.0 kB CSS (0) — — · — · —
Text 12.0 kB (0) · 6.1 kB CSS (0) — — · — · —
Timestamp 28.4 kB (0) · 11.5 kB CSS (0) — — · — · —
lab/EmojiPicker 123.3 kB (0) · 751 B CSS (0) — — · — · —
Heading 12.9 kB (−1 B) · 6.1 kB CSS (0) — — · — · —
Tokenizer 116.4 kB (−2 B) · 22.0 kB CSS (0) — — · — · —
lab/LineClamp 14.6 kB (−2 B) · 168 B CSS (0) — — · — · —
charts/ChartLegend 42.6 kB (−4 B) · 224 B CSS (0) — — · — · —

Package size: @astryxdesign/core 8.03 MB packed (+95 B); no new dependencies.

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@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.

Requesting changes: the hook reorder, tests and spec sentence look right, but the description cites a performance rule that does not exist.

  • The description cites architecture:component-performance INV18, but no such record exists; the rule it paraphrases is architecture:react-component-runtime INV18 ("Layout is read as little as possible"), which covers layout reads only, so cite that clause and what it covers, or drop the citation.

This needs only a description edit. Two optional points: checkVisibility() forces a style update rather than layout, so the release note and the new code comment could say that; and inside a live region the hook no longer re-arms content hidden by CSS, which matters only if an ancestor's live role changes while the owner stays mounted. CI has not run on this draft head.

Claims and files checked

Review mode: same-head; reason: none

  • Claim: inside a live region, EmptyState read its visibility before deciding to stay silent. Verified: the base's first guard calls checkVisibility() before the live-region check (useAnnounceRenderedText.ts, base lines 202-215).
  • Claim: the hidden-ancestor and live-region checks now run before the visibility read, and the decisions are the same. Verified (head lines 202-217): the hidden check already ran first on the base, and one re-arm difference remains when an ancestor's live role changes while the content is hidden by CSS (non-blocking).
  • Claim: the owners that skip the first render are EmptyState, Spinner and ChatComposer. Verified (AnnounceRenderedText.tsx:25, Spinner.tsx:487, ChatComposer.tsx:512).
  • Claim: a forced read during a commit can cost a frame on a busy page. Not measured in the pull request; stated as a possibility only.
  • Claim: a performance record's INV18 asks components to read layout and style as little as possible. False: the named record does not exist, and the matching INV18 covers layout reads only.
  • Claim: EmptyState's AR3 and the status-announcement spec's FR4 require silence inside a live region. Verified (FR4; FR11 applies FR4 inside a mounted live container; the AR3 verification row).
  • Claim: AR3's text now says what its verification row already tested. Verified (EmptyState.spec.md:145-146 against the AR3 row).
  • Claim: the new live-region case fails on the base. Verified by reading: the base calls the stubbed checkVisibility() once before returning.
  • Claim: outside a live region the visibility read still happens and the message is announced once. Verified (EmptyState.announce.test.tsx:164-189; head lines 214-217).
  • Claim: the scope is EmptyState and the announcement hook, with no new public API, visual representation, default or interaction model. Verified.
  • Claim: the public text carries no internal context. Verified.
  • Claim: the overlapping open fix in the same hook changes a different hunk. Verified: it changes the renderedWithPage initialiser (lines 185-193), apart from this change's lines 202-217.
  • Claim: the listed test, type, lint, knowledge and changeset checks pass. Not verified: CI skipped every job on the draft head, and dependencies could not be installed for this review.
  • Release note: inside a live region EmptyState no longer forces a style and layout read, and announcements are unchanged. Verified that the read is gone and announcements match; "layout" overstates the saved work (non-blocking).
  • File .changeset/emptystate-live-ancestor-before-visibility.md: wording note (non-blocking).
  • File docs/specs/components/EmptyState/EmptyState.spec.md: clear.
  • File packages/core/src/EmptyState/EmptyState.announce.test.tsx: clear.
  • File packages/core/src/hooks/useAnnounceRenderedText.ts: clear; comment wording and re-arm notes (non-blocking).

Automated review (maintainer link)

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec ae383da

@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.

Approved pending CI: the hook reorder, the two tests, the spec sentence and the description all check out, and CI is still running on this head; the EmptyState announcement tests, the type check and lint have already passed there.

Next step: let the remaining required checks finish; the merge guard needs them green before merge.

One optional point: inside a live region the hook no longer re-arms content hidden by CSS, which matters only if an ancestor's live role changes while the owner stays mounted.

Claims and files checked

Review mode: same-head; reason: none

  • changed rules (0): none
  • Claim: inside a live region, EmptyState read its visibility before deciding to stay silent. Verified: the base's first guard calls checkVisibility() before the live-region check (useAnnounceRenderedText.ts, base lines 202-215).
  • Claim: every such EmptyState pays a forced style update for no announcement. Verified: on the base the read runs on every render of the owner before the silent return.
  • Claim: announcements do not change, and the decisions are the same with only their order changed. Verified (head lines 202-217): the hidden check already ran first on the base; one re-arm difference remains when an ancestor's live role changes while the content is hidden by CSS (non-blocking).
  • Claim: the owners that skip the first render are EmptyState, Spinner and ChatComposer. Verified (AnnounceRenderedText.tsx:25, Spinner.tsx:487, ChatComposer.tsx:512).
  • Claim: a forced style update during a commit adds main-thread work on a busy page. Stated as a prediction; not measured.
  • Claim: the runtime record's rule on layout reads asks components to read layout as little as possible, and an unneeded style read is the same kind of work. Verified: the rule reads "Layout is read as little as possible"; the second half is the author's own reasoning.
  • Claim: EmptyState's accessibility rule and the status-announcement spec require silence inside a live container. Verified (the spec's live-container rule, which its appear-later rule applies inside a mounted live container; the EmptyState verification row).
  • Claim: the EmptyState rule text now says what its verification row already tested. Verified (EmptyState.spec.md:145-146 against the verification row).
  • Claim: the new live-container case fails on the base, where checkVisibility is called once. Verified by reading: the base calls the stubbed checkVisibility() once, in the Effect after the empty state mounts, before returning.
  • Claim: outside a live container the visibility read still happens and the message is announced once. Verified (EmptyState.announce.test.tsx:164-189; head lines 214-217).
  • Claim: the scope is EmptyState and the announcement hook, with no new public API, visual representation, default or interaction model. Verified.
  • Claim: the public text carries no internal context. Verified.
  • Claim: the overlapping open fix in the same hook changes a different hunk. Verified: it changes the renderedWithPage initialiser (lines 185-193), apart from this change's lines 202-217.
  • Claim: the listed test, type, lint, knowledge, comment-provenance and changeset checks pass. Partly verified: on this head CI's type check, lint and the unit-test shard that runs the EmptyState announcement file (all 10 cases passing) succeeded; two unit-test shards and the browser interaction jobs were still running.
  • Release note: inside a live region EmptyState no longer forces a style update when it appears; it checks for the live region first; announcements are unchanged. Verified.
  • File .changeset/emptystate-live-ancestor-before-visibility.md: clear.
  • File docs/specs/components/EmptyState/EmptyState.spec.md: clear.
  • File packages/core/src/EmptyState/EmptyState.announce.test.tsx: clear.
  • File packages/core/src/hooks/useAnnounceRenderedText.ts: clear; re-arm note (non-blocking).

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 24, 2026 19:46
@cixzhang
cixzhang merged commit e10edef into main Nov 24, 2026
162 checks passed
@github-actions
github-actions Bot deleted the lane2/emptystate-live-ancestor-first branch November 25, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — ae383da4 Deployed Nov 24, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant