Skip to content

fix(EmptyState): remove the root's live role - #7892

Closed
harjothkhara wants to merge 18 commits into
meta:mainfrom
harjothkhara:fix/empty-state-no-live-role
Closed

harjothkhara wants to merge 18 commits into
meta:mainfrom
harjothkhara:fix/empty-state-no-live-role

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

User impact

EmptyState always put role="status" on its root. It usually mounts after a search or load, already holding its text, so screen readers may or may not announce it. When it is ordinary page content, it is not a status message at all.

Problem and solution fit

A live region only announces changes made after it is in the tree. EmptyState mounts with its title and description in place, so the role adds an unreliable announcement rather than a dependable one. AST-086 FR2 sends a message that mounts with its element through the shared announcement channel instead.

spec:AST-086 FR11 (current) decides when: a message present at page load, or rendered on the server, is not announced; one inserted later, or whose text changes later, is announced once. Inside a mounted live container the container delivers it (FR4). architecture:react-component-runtime INV10 puts every own-content announcement in one unexported module, so EmptyState holds no Effect of its own.

Expected behavior and authority

AST-086 FR2 (current): an element that mounts together with its text must not carry a live role or aria-live. Its impact list names EmptyState.

Smallest restoration

  • EmptyState.tsx: drop the hard-coded role="status". A role the caller passes now reaches the root instead of being overwritten.
  • JSDoc, EmptyState.doc.mjs anatomy wording and the draft EmptyState.spec.md no longer describe a status region.
  • useAnnounceRenderedText (internal, unexported) gains a skipFirstRender option and a politeness option. With skipFirstRender, text present when its owner rendered with the page (before the first paint, or while hydrating) is remembered silently; text that appears or changes later is announced once; content inside a mounted live container is left to it. The page-load check, DOM read and channel write all live in this one module (INV10).
  • EmptyState's title and description render inside an internal AnnounceRenderedText wrapper that only calls the hook. EmptyState stays directive-free and server-renderable: the RSC boundary test admits that wrapper as a client island, and on the server it renders a plain div because effects never run there (FR12). The icon and actions are not announced.
  • Consumer tests: Comments looks for its error Banner rather than the page's shared alert region, MobileTokenizer's animation-frame stub runs on the next microtask (a real frame never runs before requestAnimationFrame returns), and ListInput's last-item removal now hears the empty message (below).
  • MobileTokenizer.test.tsx: a test selector update ([role="status"] to .astryx-empty-state), no production change.

Evidence

  • Reproduction before the change: with the new test on unchanged source, EmptyState.test.tsx fails 2 of 23. The root has a role attribute, and a caller's role="region" is replaced by status.
  • Result after the change: the root has no role or aria-live, and the title and description are still in the root's text.
  • EmptyState.announce.test.tsx: present at page load → nothing reaches the shared region; inserted later (StrictMode) → "No results Try another search." exactly once; a later title change → the new title once; inside a role="log" → nothing through the channel; a server render plus hydration → no live role and nothing announced. Removing the first-render skip, the live-container skip, the dedupe, or the hydration check each fails its case; on main the appear and server cases fail.

Chrome 156 (headless), Storybook from main (cb489ffbcc8) and from this head:

State main head
TableFiltering, a filter applied that leaves no rows (EmptyState appears) root role="status" mounted already holding "No data"; nothing written to the shared region root has no role; the shared polite region receives "No data" once
EmptyState Full Example story root role="status" root has no role; announced once, because Storybook renders a story after its preview's first paint, so it counts as inserted after page load (FR11; a client-rendered route change behaves the same)

(The Chrome rows were captured before the change to the shared hook; the announce-on-appear behavior they show is unchanged, and the unit tests above cover the final shape.)

  • Representative unchanged path: heading level, decorative icon, slot order, compact variant, root prop/ref/style composition and theming targets keep their existing tests.
  • Regression test or other mutation-sensitive proof: does not make the root a live region fails if any role or aria-live returns to the root.

DOM and accessibility-tree proof only; no spoken-output claim.

Patch or breaking?

Patch. Under AST-017 FR53 the component absorbs the change: an empty state that appears is still announced, now through the shared channel, so no app edits code. What changes for assistive technology is listed in the changeset. In the lab ListInput, removing the last item makes its empty state appear in the same frame as "Removed guest 1."; joining same-frame messages is the shared channel's job under AST-086 FR9, not this change.

Writing rubric results

Record touched: packages/core/src/EmptyState/EmptyState.spec.md.

  • R1 narration: two "no longer" phrasings found in my edits; rewritten as present tense.
  • R2 research in the record: none.
  • R3 evidence naming a change: none; FR1 cites spec:AST-086 FR2.
  • R4 rejected alternatives over one line or outside a decision: none.
  • R5 pull request or issue references remaining: none.
  • R6 ruled open questions still listing options: none; the record has no open questions.

Scope

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

Testing

  • pnpm vitest run packages/core/src/EmptyState packages/core/src/hooks packages/core/src/serverSafeComponents.test.ts packages/core/src/Selector/Selector.test.tsx packages/core/src/Chat packages/core/src/FieldStatus packages/lab/src/ListInput packages/lab/src/MobileTokenizer packages/lab/src/Comments: 1316 passed
  • pnpm vitest run packages/core/src/EmptyState packages/lab/src/MobileTokenizer packages/core/src/theme/themingTargets.test.ts packages/core/src/docPropReferences.test.ts: 463 passed (before the announcement change)
  • pnpm -F @astryxdesign/core typecheck, pnpm lint:strict, pnpm check:knowledge, pnpm check:sync, pnpm check:changesets: pass
  • pnpm vitest run packages/core/src packages/lab/src: 13490 passed, 4 failed in untouched files. postinstall.test.mjs fails the same way on main locally. DateTimeInputTouch and Markdown.fr23.perf pass when run alone.

Changeset: @astryxdesign/core patch, [fix].

Fixes #7860

EmptyState rendered role="status" on its root, so it mounted as a live region already holding its text. AST-086 FR2 says such an element must carry no live role; the owner of the empty result announces it through the shared channel.
@vercel

vercel Bot commented Oct 22, 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 Oct 24, 2026 5:59pm UTC

Request Review

@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 labels Oct 22, 2026
@astracat-bot

astracat-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 24, 2026, 6:34 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

EmptyState (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 143 -
Complexity N/A Medium (11) -
ListInput (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1760 -
Complexity N/A Very High (274) -
MobileTokenizer (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 598 -
Complexity N/A Very High (64) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB
@astryxdesign/lab N/A 4.6KB 1.9KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 502 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | 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.

Removing role="status" from EmptyState matches AST-086 FR2 and its tests pass, but approval waits on a maintainer decision. The PR makes the code that produced an empty result responsible for announcing it, which no current spec settles, and that choice decides whether this can ship as a patch under AST-017 FR53, since a persistent EmptyState whose title changes would then need app code to stay announced. A maintainer needs to approve caller-owned announcement as a patch [fix], or ask for EmptyState to announce through the shared channel itself, or for the change to wait for a minor as [breaking]; one wording fix in AR3 is noted inline.

[Automated review]

Comment on lines +136 to +139
- **AR3 — No live region.** The root carries no live role or `aria-live` and does
not move focus. The code that produced the empty result announces it through
the shared channel when needed (`spec:AST-086` FR2). Action controls keep
their own names, roles, and behavior.

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.

AR3 says the root "carries no live role or aria-live", but ORD1 now lets a caller's role reach the root, so a caller can still make it a live region. Wording it as what the component adds, for example "EmptyState adds no live role or aria-live", keeps AR3 true. Who announces the empty result is the open maintainer question on this PR.

A caller's role still reaches the root, so state AR3 and related lines as what EmptyState adds.

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

Removing role="status" from EmptyState matches AST-086 FR2, and the record now says what EmptyState adds, but approval still waits on a maintainer decision. Approval needs a maintainer to provide or identify the spec that names who announces an empty result: the PR gives that job to the code that produced it, which no current spec states, and that choice decides whether this can ship as a patch under AST-017 FR53, since a persistent EmptyState whose title changes would then need app code to stay announced. A maintainer needs to approve caller-owned announcement as a patch [fix], ask for EmptyState to announce through the shared channel itself, or hold the change for a declared minor as [breaking]; if callers own it, Astryx's own MobileTokenizer "No results found" message announces nothing yet.

[Automated review]

Comment thread .changeset/empty-state-no-live-role.md Outdated
'@astryxdesign/core': patch
---

[fix] EmptyState's root no longer carries `role="status"`; EmptyState adds no live role or `aria-live`. It usually mounts already holding its text, so the announcement was unreliable, and as ordinary page content it is not a status message. This conforms to spec:AST-086 FR2, which gives any announcement of an empty result to the code that produced it (for example through `useAnnounce`). A `role` you pass now reaches the root instead of being replaced. Tests that found EmptyState with `getByRole('status')` need another selector.

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.

AST-086 FR2 says only that "the owner announces through the shared announcement channel"; it names no owner, so this sentence presents as AST-086's rule the ownership that the open maintainer question has to settle. Once a maintainer rules, this line can cite that decision (for example an approved AR3) instead.

…loads

An EmptyState rendered with the page (before the first paint, or while
hydrating) announces nothing. One that appears later, after a search or a
load returns nothing, announces its title and description once through the
shared polite live region (spec:AST-086 FR2), so apps need no change and
the fix stays a patch.

EmptyState stays presentational: its message renders inside an internal
AnnounceOnInsert, which owns the observation. useIsInsertedAfterLoad
holds the 'rendered with the page or inserted later' test useEntryAnimation
already made, so both share it. Neither is public. Tests that found the
component's own alert or relied on a synchronous animation frame now ignore
the page's shared live regions or use a microtask, and ListInput's last-item
removal now announces the empty message.
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Oct 22, 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.

Removing role="status" from EmptyState matches AST-086 FR2, but approval waits on a maintainer decision: draft AR3 now has EmptyState announce itself once when it mounts after the first animation frame and stay silent when its text changes, and a maintainer needs to approve that ownership and the patch [fix] class under AST-017 FR53, or choose caller-owned announcement or a [breaking] change for a declared minor. If EmptyState keeps announcing itself, these need fixing:

  • An EmptyState added inside a live container, such as ChatMessageList's role="log", is also announced through the shared channel, which AST-086 FR4 rules out; skipping the channel when the root or an ancestor is live, as ChatTypingIndicator does, fixes it and covers a caller's role="status" too.
  • serverSafeComponents.test.ts now fails in CI because EmptyState.tsx imports the 'use client' module useIsInsertedAfterLoad.tsx.
  • Removing the last item in ListInput replaces "Removed guest 1." with the empty-state text in the same frame, and the changeset's "apps need no change" leaves out that a mounted EmptyState's text changes are no longer announced.

[Automated review]


useEffect(() => {
const element = ref.current;
if (!isInserted || hasSpokenRef.current || !element) {

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 announces wherever EmptyState mounts, including inside a mounted live container: ChatMessageList renders its emptyState slot inside role="log" aria-live="polite", where AST-086 FR4 says an element added with that content "MUST NOT carry its own live role or announce the same content through the channel". A caller can also now pass role="status" to the root, which gives the same words two owners (FR1). ChatTypingIndicator skips the channel with rootRef.current?.parentElement?.closest(LIVE_CONTAINER_SELECTOR); the same check from this element's parent up covers both cases.

typeScaleVars,
} from '../theme/tokens.stylex';
import type {BaseProps} from '../BaseProps';
import {AnnounceOnInsert} from '../hooks/useIsInsertedAfterLoad';

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 import makes the directive-free EmptyState reach a 'use client' module (useEffect, useRef, useState and module-level state), so serverSafeComponents.test.ts ("keeps directive-free components free of client-only imports") fails, locally and in CI's test-ui (4/4). Either keep EmptyState's import graph server-safe or mark EmptyState as a client component, as the guard's message says.

Array.from(document.querySelectorAll('[aria-live="polite"]')).some(
node => node.textContent === 'Removed guest 1.',
node =>
node.textContent === 'No guests yet Add a guest to get started.',

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 expectation now accepts that removing the last guest replaces "Removed guest 1." with the empty-state text in the same frame, so the polite region no longer carries the removal confirmation it carried before. The test should keep proving the person hears that the guest was removed.

Comment thread .changeset/empty-state-no-live-role.md Outdated
'@astryxdesign/core': patch
---

[fix] EmptyState's root no longer carries `role="status"`, so it is not a live region that mounts already holding its text, which screen readers announce unreliably (`spec:AST-086` FR2). An EmptyState that renders with the page announces nothing. One that appears later, for example after a search or a load returns nothing, announces its title and description once through the shared polite live region, so apps need no change. A `role` you pass now reaches the root instead of being replaced. Tests that found EmptyState with `getByRole('status')` need another selector.

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.

"so apps need no change" leaves out that a mounted EmptyState whose text changes is no longer announced, and that tests expecting a single alert or status element can now match the shared regions (the Comments.test.tsx change in this PR). AST-017 FR53 asks the Changeset to name the old and new behavior. "An EmptyState that renders with the page announces nothing" also holds only when it mounts before the first animation frame or while hydrating; the Storybook Full Example story announces at load.

cixzhang added a commit that referenced this pull request Oct 22, 2026
## Exact decision needed

Whether merge or stable release may wait on real assistive-technology (NVDA, VoiceOver) evidence that contributors cannot produce.

## Existing authority searched

- `spec:AST-009` (current): FR4/FR8/FR17–FR19 required an explicit trigger classification, a named real-AT matrix, a scenario, and a durable release-block record, and blocked the first stable release until real-AT receipts passed or an owner exception applied.
- Linked records that restated the block or required screen-reader checks: `spec:AST-001` (browser evidence and FR7 row), `module:Table/useTableRowStatus` AR6, `module:Table/useTableColumnResize` verification, `spec:AST-056` (browser evidence line), `spec:AST-021` (release boundary phrase), `spec:AST-086` (FR6 real-AT row and platform line), `component:FieldStatus` AR5 and its verification row, `spec:AST-020` FR6 ("real-AT contract").
- Open PRs that add release-block sections to AST-009: #7732, #7275, #7272. Under this record those sections are no longer needed.

## Decision

- No requirement gates merge or release on evidence that cannot be produced (Intent, FR17, DEC-4).
- Merge and stable release need only the unit, DOM, accessibility-tree, axe, and real-browser evidence the owning records require (FR17).
- Announcements are proved by their routing: which element or channel carries them, their text, urgency, and update count per occasion (FR4, FR19).
- Real-AT observation is recommended follow-up when an outcome depends on AT behavior, may be tracked in a public issue, and holds no pull request or release (FR1–FR6, FR18).
- A change with an AT-dependent claim says so and names its lower-layer evidence; no matrix, scenario, or release record is needed to merge (FR8).
- Evidence-layer boundaries, the representative matrix, failure handling, and durable receipts stay, scoped to when a real-AT check runs.
- The exception process (old FR23–FR26) is removed because nothing remains to except.

## Rejected alternatives

- Holding stable releases until named real-AT receipts pass: fixes for known accessibility defects stall when no contributor can run the required pairings.

## Claim scope and non-goals

Only the evidence bar for merge and release, and the status of real-AT observation. Component accessibility requirements, evidence-layer boundaries, and focus/announcement behavior stay with their owners.

## Evidence and implementation relationship

Status-announcement conformance PRs (#7869, #7870, #7871, #7892, #7900, #7910) stall on the old real-AT release-block requirement because nobody in the review loop can run NVDA or VoiceOver. No implementation is included.

## Writing rubric results

- R1 narration: none; present-tense rules throughout. The two earlier holds are described as current follow-ups.
- R2 research in the record: none.
- R3 evidence naming a change: none; the earlier hold sections that named pull requests are replaced by the facts (story names and claims).
- R4 rejected alternatives over one line or outside a decision: one per decision, one line each.
- R5 pull request or issue references remaining: none in AST-009 or the edited lines.
- R6 ruled open questions still listing options: none.

## Scope

- [x] This PR contains specification records only.
- [x] It records observable behavior and preserves equivalent internal implementations.
- [x] Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract.
- [x] Verification states the evidence layer and failure signal without prescribing CI job/workflow topology.
- [x] It records one intentional durable decision, not a rescue for a separable tagalong.
- [x] The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision.
- [x] Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them.
- [x] Public text and artifacts contain no internal Meta context.

## Validation

- `pnpm check:knowledge`
- Prettier
- `git diff --check`
… container

Inside a mounted live container such as ChatMessageList's log, the
container delivers what is added to it, so AnnounceOnInsert does not also
announce through the shared channel (spec:AST-086 FR4). The changeset
lists what changes for assistive technology.
EmptyState now renders AnnounceOnInsert, which needs client APIs, so it
carries 'use client' like Field and Layout and still renders from server
components. useEntryAnimation keeps its own first-paint check unchanged.
@harjothkhara

Copy link
Copy Markdown
Contributor Author

test-ui (4/4) fails in serverSafeComponents.test.ts ("keeps directive-free components free of client-only imports"): EmptyState.tsx now imports useIsInsertedAfterLoad.tsx, which starts with 'use client'. I can push a fix for this to the branch if it would help, either by keeping EmptyState's import graph server-safe or by marking it a client component. Which do you prefer, or are you already on it?

…FirstRender option

Option A of the announce-on-appear decision: the existing
useAnnounceRenderedText gains skipFirstRender, so text present when its
owner first rendered with the page stays silent and text that appears or
changes later is announced once. Content inside a mounted live container is
left to it (spec:AST-086 FR4). EmptyState's message renders inside the
internal AnnounceRenderedText, which calls the hook; the separate
useIsInsertedAfterLoad module goes away.
…nt island

EmptyState stays directive-free and server-renderable. The
AnnounceRenderedText wrapper is admitted as a client island in the RSC
boundary test: on the server it only renders its div, since effects never
run there, so a server-rendered empty state announces nothing.
Covers spec:AST-086 FR12's server row: the server HTML carries no live
role, and hydrating it announces nothing.
So the components that adopt the helper next can route errors
assertively (spec:AST-086 FR5); the default stays polite.
@github-actions github-actions Bot removed the needs:design-review Affects visuals — Design should review label Oct 23, 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.

Dropping role="status" and having EmptyState announce itself after page load matches AST-086, but approval waits on an engineering owner deciding one draft requirement: AR3 now says EmptyState announces only its title and description, leaving out action labels, which AST-086 FR12 ("the element's rendered text") does not settle. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Separately from that decision, these need changes:

  • Page load ends one animation frame after the hook module loads (useAnnounceRenderedText.ts:50-57), but AST-086 FR11 ends it when the document finishes loading, so an empty state inserted while the page is still loading is announced and one first rendered by a lazily loaded route is not; AR3, the changeset and the option's JSDoc repeat the first-frame rule.
  • AnnounceRenderedText always passes isShown: true, so an EmptyState rendered hidden is announced while invisible and stays silent when shown (FR12, FR13).
  • Removing ListInput's last item replaces "Removed guest 1." with the empty-state text in the same frame, against FR9's joined messages, and the updated test asserts the drop.
  • The FR11–FR13 verification states (route change, client navigation, insertion before load, hide/show) need tests, and the PR description still describes the earlier AnnounceOnInsert design.

[Automated review]

Comment on lines +50 to +57
// Whether the page's first paint has happened. Server-rendered owners are
// covered by useIsHydrating instead: hydration can run after this turns true.
let initialPaintComplete = false;
if (typeof window !== 'undefined') {
requestAnimationFrame(() => {
initialPaintComplete = true;
});
}

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.

spec:AST-086 FR11 defines page load as "everything committed until the document finishes loading", and its verification row requires silence for a message "inserted after first render but before the document finishes loading". This flag flips one animation frame after the module evaluates, so an EmptyState inserted while the page is still loading is announced, and one first rendered by a lazily loaded module after load is silent. Capturing isHydrating || document.readyState !== 'complete' at first render matches FR11 without a module-level frame.

*/
export function AnnounceRenderedText(props: HTMLAttributes<HTMLDivElement>) {
const ref = useRef<HTMLDivElement>(null);
useAnnounceRenderedText(ref, true, '', {skipFirstRender: true});

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.

isShown is always true, so an EmptyState rendered with hidden (or under a hidden ancestor) after load is announced while invisible, and removing hidden announces nothing. AST-086 FR12 asks the announcement to re-arm when the element is hidden, and FR13 to do no work while it is hidden.

Array.from(document.querySelectorAll('[aria-live="polite"]')).some(
node => node.textContent === 'Removed guest 1.',
node =>
node.textContent === 'No guests yet Add a guest to get started.',

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 now asserts that the empty-state text replaces "Removed guest 1." in the same frame. AST-086 FR9 requires same-frame messages to be joined with none dropped, so the test should expect the joined "Removed guest 1. No guests yet Add a guest to get started." once useAnnounce joins them.

Comment on lines +139 to +141
page (before the first paint, or while hydrating), it announces nothing. When
it appears, or its message changes, later, it announces its title and
description once through the shared polite channel (`spec:AST-086` FR2, FR11).

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.

"before the first paint, or while hydrating" redefines page load; AST-086 FR11 says page load lasts until the document finishes loading. "its title and description" also sets the announced message, which FR12 ("the element's rendered text") does not settle; an engineering owner decides that scope.

…den root stays silent

spec:AST-086 FR11 draws the line at the page load, so the helper captures
document.readyState at mount instead of the first animation frame after its
module evaluated: content inserted while the document is still loading
stays silent, and a lazily loaded module rendering after load announces.
A root hidden with the hidden attribute or aria-hidden re-arms instead of
announcing, and announces once when shown (FR12). The politeness option
waits for the adopter that needs it.
…ment; EmptyState AR3 names its message

With the shared channel's same-frame join on main (spec:AST-086 FR9), the
removal and the empty state that appears in the same frame are announced
together, in order. AR3 now states the announced message exactly: the
title and description, without content hidden from assistive technology;
action labels are not part of it.

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

Removing role="status" from EmptyState and having it announce itself once after page load matches AST-086, but approval waits on an engineering owner deciding one draft requirement: AR3 now announces only the title and description and leaves out action labels, which AST-086 FR12 ("the element's rendered text") does not settle. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Separately from that decision, these need changes:

  • A title change, or removing hidden, while the document is still loading is announced, because useAnnounceRenderedText.ts checks page load only on the Effect's first run; AST-086 FR11 keeps both silent, and an EmptyState test for insertion before the document finishes loading is still missing.
  • AR3 and the skipFirstRender JSDoc describe page load as "before the first paint", while FR11 and the code use the document finishing loading.

[Automated review]

return;
}
spokenRef.current = spoken;
if (skipFirstRender && isFirstRun && renderedWithPage) {

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.

Only the Effect's first run checks page load, so a title change, or removing hidden, while the document is still loading is announced; spec:AST-086 FR11 keeps both silent ("A message present during page load is not announced"). Treating every run before the document finishes loading as page load closes it:

if (
  skipFirstRender &&
  ((isFirstRun && renderedWithPage) || document.readyState !== 'complete')
) {
  return;
}

EmptyState tests for both states, and for an insertion after first render but before load (the FR11 verification row), would pin it.

export interface AnnounceRenderedTextOptions {
/**
* Text present when the owner first rendered with the page (before its
* first paint, or while hydrating) is not announced; text that appears or

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.

"before its first paint" is not the boundary the code uses (document.readyState !== 'complete', line 116) or the one spec:AST-086 FR11 sets ("until the document finishes loading"). Suggest: "Text present when the owner first rendered with the page (before the document finished loading, or while hydrating) is not announced".

without moving focus; action controls keep their own names, roles, and behavior.
- **AR3 — No live region; announced when it appears.** EmptyState adds no live
role or `aria-live` to the root and does not move focus. Rendered with the
page (before the first paint, or while hydrating), it announces nothing. When

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.

spec:AST-086 FR11 ends page load when the document finishes loading, which the implementation follows; "before the first paint" describes an earlier boundary. Suggest: "Rendered with the page (before the document finishes loading, or while hydrating), it announces nothing."

Comment on lines +141 to +143
through the shared polite channel (`spec:AST-086` FR2, FR11). The message is
the title and description, without content hidden from assistive technology;
action labels are not part of it. Action controls keep their own names,

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 sets which words EmptyState announces: the title and description, without action labels. spec:AST-086 FR12 says an adopter announces "the element's rendered text" without naming EmptyState's element, so this scope needs an engineering owner to approve or reject it.

cixzhang added a commit that referenced this pull request Oct 25, 2026
…ive root (#8294)

<!-- template: bug-fix.md -->

## User impact

A screen-reader user who filters a table or searches until nothing matches may not hear that nothing was found. EmptyState's root was a `role="status"` live region that mounts already holding its text, which screen readers announce unreliably. After this change, an EmptyState that appears after the page has loaded is announced once, title and description, through the shared polite region. One that is part of the page when it loads stays silent.

Rebuilds #7892 by @harjothkhara on current `main`, with the loading-time fix its last review asked for (credited in the commit). Resolves the EmptyState part of #7860.

## Problem and solution fit

- **Why it happens:** the root carries `role="status"` and is born with its text, so whether it is spoken depends on the screen reader.
- **Why it hurts:** the "nothing found" outcome of a search or filter can go unannounced, or be announced at page load when nothing happened.
- **Why it matters:** `spec:AST-086` (current) routes announcements through the shared channel and decides when content that appears is announced (FR11).

The root drops the role. A small internal client island beside the message, `AnnounceRenderedText`, calls the unexported helper `useAnnounceRenderedText` with `skipFirstRender`. It stays silent for content rendered or changed before the document finished loading or while hydrating, while hidden, and inside a mounted live container, which delivers it instead (FR4). It announces once when the EmptyState appears or its message changes later (FR11). EmptyState itself stays server-renderable: the island is admitted by the server-safe guard and does nothing on the server (FR12). The announcement Effects live only in the helper module (`architecture:react-component-runtime` INV10).

## Expected behavior and authority

`spec:AST-086` FR2, FR4, FR11, FR12 (current), and `architecture:react-component-runtime` INV10 (current). Component record AR3 states what is announced: the message is the title and description, without content hidden from assistive technology; action labels are not part of it.

## Smallest restoration

- `EmptyState.tsx`: no `role="status"`; the text group is wrapped in `AnnounceRenderedText`.
- `hooks/AnnounceRenderedText.tsx` (internal, `'use client'`) and `hooks/useAnnounceRenderedText.ts`: the `skipFirstRender` option, page-load detection read when announcing, the hidden and live-container checks.
- `serverSafeComponents.test.ts`: admits the client island.
- `EmptyState.spec.md` AR3, `EmptyState.doc.mjs` anatomy line, patch `[fix]` changeset.
- Tests that selected EmptyState by `role="status"`, and ListInput's expectation of the joined same-frame announcement (FR9).

## Evidence

- Before: the root is `role="status"` and mounts with its text.
- After (jsdom, StrictMode): silent when rendered with the page; silent for a title change or a `hidden` removal while the document is still loading; once when it appears later; once when its message changes later; silent inside a `role="log"`; silent from a server render and its hydration; action labels and the icon are never spoken.
- Mutation-sensitive: removing the load-time read when announcing fails the two loading cases.

## Scope

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

## Testing

- `pnpm vitest run packages/core/src/EmptyState packages/core/src/hooks packages/core/src/serverSafeComponents.test.ts packages/lab/src/ListInput packages/lab/src/Comments packages/lab/src/MobileTokenizer packages/core/src/Selector` (920 tests)
- `tsc` (core) clean; ESLint clean on the touched files; `check-use-client` clean.


## Note: CSS-hidden content and older engines

An EmptyState inside content hidden by CSS (for example a closed Collapsible) stays silent until a render shows it; the helper asks the engine through `Element.checkVisibility()`. Engines without `checkVisibility` (Safari before 17.4) keep the previous behavior: there, such an EmptyState is announced when it appears even while hidden by CSS. A `getClientRects()` fallback was not used because environments without layout report no boxes for any element and would silence every announcement. Content revealed without a re-render of its owner is announced on the owner's next render, with nothing watching while hidden (`spec:AST-086` FR12, FR13).

Co-authored-by: Harjoth Khara <[email protected]>
@cixzhang

Copy link
Copy Markdown
Contributor

Closing as superseded by #8294. Posted by Cindy's agent on her behalf.

@cixzhang cixzhang closed this Oct 28, 2026

This branch was successfully deployed

1 active deployment
Preview — ef4ac241 Deployed Oct 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. 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] EmptyState: the root is a live region that mounts with its content

2 participants