Skip to content

fix(EmptyState): announce once when it appears after load, not as a live root - #8294

Merged
cixzhang merged 4 commits into
mainfrom
fix/empty-state-announce-on-appear
Oct 25, 2026
Merged

cixzhang merged 4 commits into
mainfrom
fix/empty-state-announce-on-appear

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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/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]

…ive root

EmptyState's root carried role="status", so it was a live region that
mounted already holding its text, which screen readers announce
unreliably (spec:AST-086 FR2). The root drops the role. An internal client
island beside the message announces the title and description once
through the shared polite channel when EmptyState appears, or its message
changes, after the document finished loading; it stays silent while the
page loads or hydrates, while hidden, and inside a live container, which
delivers it (FR4, FR11, FR12). EmptyState stays server-renderable. AR3
states the message: the title and description, without content hidden
from assistive technology; action labels are not part of it.

Rebuilds #7892 on main with the loading-time fix.

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

vercel Bot commented Oct 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 Oct 25, 2026 2:39am UTC

Request Review

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

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 25, 2026, 3:05 AM UTC

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@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 brings EmptyState in line with the status-announcement spec, and approval now waits on one spec decision: the draft EmptyState record's AR3 adds a rule that the announced message is the title and description only, never the action labels, which no current spec states yet. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. Two smaller points are worth a look:

  • An EmptyState revealed by removing hidden from a parent that does not re-render it is never announced, because the hidden check in useAnnounceRenderedText runs only when EmptyState re-renders.
  • Content marked hidden inside the description is included in the announcement, since the text helper strips only aria-hidden content.

[Automated review]

const isFirstRun = isFirstRunRef.current;
isFirstRunRef.current = false;
const element = ref.current;
if (!isShown || element?.closest('[hidden], [aria-hidden="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.

This hidden check runs only when EmptyState re-renders. When a parent toggles hidden around a stable EmptyState element (for example a panel that receives it as children), the reveal never reaches this Effect: an EmptyState rendered hidden during load and revealed after load announces nothing, and one shown, hidden and shown again announces only the first time. Consider noticing the reveal itself, or saying in AR3 that reveals are seen when EmptyState re-renders.


/** The rendered text an assistive technology would read from `element`. */
function renderedText(element: HTMLElement): string {
export function renderedText(element: HTMLElement): string {

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.

renderedText removes only aria-hidden descendants, so a hidden span inside the description is spoken (No results Try another search. internal-note in a quick check). Draft AR3 promises "without content hidden from assistive technology"; dropping [hidden] descendants from the clone, or wording AR3 as aria-hidden content, would make the two agree.

Comment on lines +142 to +144
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 sentence decides what EmptyState's message is: the title and description, never the action labels. The current status-announcement spec leaves that decision to the component record, and this record is draft, so the rule needs an engineering owner's exact-head approval (/approve-spec <full head SHA>).

renderedText removed only aria-hidden content, so text inside an element
with the `hidden` attribute, which assistive technology does not read, was
announced. It now removes `[hidden]` too, in both the per-block filter and
the text read. The skipFirstRender docs note that a reveal done by script
outside React is read on the owner's next render, since watching while
hidden would hold a resource (react-component-runtime INV5).

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

@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 brings EmptyState in line with the status-announcement spec, and approval now waits on one spec decision: the draft EmptyState record's AR3 adds that the announced message is the title and description only, never the action labels, which no current spec states yet. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. The earlier point about hidden description text is fixed, and two smaller, non-blocking points remain:

  • An EmptyState revealed by removing hidden from an ancestor that does not re-render it is never announced, because the hidden check in useAnnounceRenderedText runs only when EmptyState re-renders.
  • A description made of several block elements is announced with the words at the block edges run together (for example filtersTry), because blockText splits only the heading and the description.

[Automated review]

Comment on lines +54 to +60
function blockText(element: HTMLElement): string {
return Array.from(element.children)
.filter(child => !child.matches('[aria-hidden="true"], [hidden]'))
.map(child => renderedText(child as HTMLElement))
.filter(part => part !== '')
.join(' ');
}

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.

blockText splits only the text group's direct children, so block elements inside a description run together: a description of <p>Nothing matched your filters</p><p>Try another search</p> is announced as No results Nothing matched your filtersTry another search. Reading each block-level descendant as its own block, as this function already does for the heading and the description, would keep the words apart (AST-086 FR7, "The announced words match the shown words").

renderedText read the clone's textContent, so two block elements inside a
description ran together ("Try again.Later."). Each block now ends in a
space before the text is read, and the hidden-content removal shares one
selector. The skipFirstRender docs cite why a reveal by script outside
React is read on the owner's next render: no observer while hidden
(spec:AST-086 FR13, react-component-runtime INV5 and INV10).

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

@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 brings EmptyState in line with the status-announcement spec, and approval waits on one spec decision: the draft EmptyState record's AR3 adds that the announced message is the title and description only, never the action labels, which no current spec states yet. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. Two smaller, non-blocking points remain:

  • An EmptyState revealed by removing hidden from an ancestor that does not re-render it is never announced, because the hidden check in useAnnounceRenderedText runs only when EmptyState re-renders; noticing the reveal, or stating the limit in AR3, would close it.
  • The changeset could say that once an EmptyState announces, the shared status and alert regions exist and can match role queries in consumer tests, as the Comments tests found.

[Automated review]

* hydrating) is not announced; text that appears or changes later is, once
* (`spec:AST-086` FR11). Content inside a mounted live container is left to
* that container (FR4). Each child element is read as its own block. A
* script reveal outside React is read on the next render (FR13, INV5, INV10).

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 limit is wider than a script: any React parent that toggles hidden around a stable EmptyState (received as children) never re-renders it, so the reveal is never announced; in a quick check, open, close, open again after load announced nothing, while a panel re-rendering its own EmptyState announced once. Draft AR3 still says "When it appears ... later, it announces its message once". Noticing the reveal (a box shown again gains size, which a resize observer reports without work while hidden), or stating this limit in AR3, would make the two agree.

Comment thread .changeset/empty-state-no-live-role.md Outdated

[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). Apps need no code change. An EmptyState rendered or changed while the page loads announces nothing; one that appears later, or whose title or description changes later, announces its title and description once through the shared polite live region; inside a live container such as `ChatMessageList`'s log, the container announces it (`spec:AST-086` FR4). 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.

Consider one more sentence: once an EmptyState announces, the document holds the shared status and alert regions, so a consumer's own getByRole('status') or getByRole('alert') can find two matches, as Comments.test.tsx had to handle.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec c8e3515

@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 brings EmptyState in line with the status-announcement spec, and the AR3 message rule now has an engineering owner's approval, but one fix is needed before approval. An EmptyState that appears after load inside content hidden by CSS, such as a closed Collapsible, is announced although nothing is shown, because useAnnounceRenderedText treats it as shown unless it sits under a hidden or aria-hidden element; a reveal that does not re-render it is also never announced. Treating an element the browser does not render as hidden (for example with checkVisibility()), with a test for an EmptyState that appears inside a display: none ancestor, fixes the first, and noticing reveals in the shared hook would close the second.

[Automated review]

const isFirstRun = isFirstRunRef.current;
isFirstRunRef.current = false;
const element = ref.current;
if (!isShown || element?.closest('[hidden], [aria-hidden="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.

This check is the only place the island decides EmptyState is shown, and it sees only hidden and aria-hidden attributes, at render time. An EmptyState that appears after load inside a closed Collapsible (its content is display: none) is announced: in Chromium the polite region received No archived items Archived projects appear here. while the section stayed closed. A reveal that does not re-render EmptyState (opening that Collapsible, or a parent toggling hidden around a stable child) is never announced. Treating an element the browser does not render as hidden, for example element.checkVisibility?.() === false, would fix the first; noticing the reveal in this module would close the second (AST-086 FR12, FR13).

An EmptyState that appeared after load inside content hidden by CSS, such
as a closed Collapsible, was announced although nothing was shown. The
helper now also treats an element the engine reports as not rendered
(`checkVisibility()`, where the engine has it) as hidden: it stays silent
and re-arms, so the message is announced once on the render that shows
it. A reveal without a re-render is read on the owner's next render, with
nothing watching while hidden (spec:AST-086 FR12, FR13). Tests and
comments are trimmed to stay within size caps.

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

Copy link
Copy Markdown
Contributor Author

/approve-spec b47eabe

@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 brings EmptyState in line with the status-announcement spec. Its root no longer mounts as a live region, an EmptyState that appears after load is announced once with its title and description, and an engineering owner approved the AR3 message rule on this head. The closed-Collapsible case from the last review is fixed and covered by a test, so this looks ready to merge once the remaining CI jobs pass. One optional follow-up: a test that removes an ancestor's hidden attribute outside React would pin the AST-086 FR13 reveal behavior, which already works here.

[Automated review]

expect(renderedText(element)).toBe('Try again. Later.');
});

it('stays silent while hidden (attribute or CSS) or revealed during load; announces once when shown later (FR12)', async () => {

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.

Optional: spec:AST-086 FR13's verification row names an ancestor's hidden attribute removed outside React. This test toggles hidden through renders only. A case that sets hidden on a wrapper through the DOM, removes it the same way, and expects silence until EmptyState's next render and then one announcement would pin that rule. The behavior already holds on this head.

@cixzhang
cixzhang merged commit 8b74911 into main Oct 25, 2026
66 checks passed
cixzhang added a commit that referenced this pull request Oct 25, 2026
…e('status') queries (#8354)

<!-- template: docs.md -->

## User impact

A product engineer whose tests find their own status or alert with `getByRole('status')` / `getByRole('alert')` may see those queries start matching a different element after #8294: EmptyState now announces through the page's shared announcer regions, a visually hidden `role="status"` / `role="alert"` pair Astryx mounts once on `document.body` (`spec:AST-086` FR2). This changeset tells them why and how to scope the query, so the upgrade note is in the CHANGELOG.

## Change

One `[docs]` patch changeset for `@astryxdesign/core`. No code, record, or behavior change.

## Testing

- `node scripts/check-changesets.mjs` passes.
- Prettier clean.
@github-actions
github-actions Bot deleted the fix/empty-state-announce-on-appear branch October 25, 2026 06:20

This branch was successfully deployed

1 active deployment
Preview — b47eabe3 Deployed Oct 25, 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