Repository navigation
fix(EmptyState): announce once when it appears after load, not as a live root - #8294
Conversation
…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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
|
There was a problem hiding this comment.
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
hiddenfrom a parent that does not re-render it is never announced, because the hidden check inuseAnnounceRenderedTextruns only when EmptyState re-renders. - Content marked
hiddeninside the description is included in the announcement, since the text helper strips onlyaria-hiddencontent.
[Automated review]
| const isFirstRun = isFirstRunRef.current; | ||
| isFirstRunRef.current = false; | ||
| const element = ref.current; | ||
| if (!isShown || element?.closest('[hidden], [aria-hidden="true"]')) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
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
hiddenfrom an ancestor that does not re-render it is never announced, because the hidden check inuseAnnounceRenderedTextruns 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), becauseblockTextsplits only the heading and the description.
[Automated review]
| 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(' '); | ||
| } |
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
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
hiddenfrom an ancestor that does not re-render it is never announced, because the hidden check inuseAnnounceRenderedTextruns 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
statusandalertregions 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). |
There was a problem hiding this comment.
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.
|
|
||
| [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. |
There was a problem hiding this comment.
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.
|
/approve-spec c8e3515 |
There was a problem hiding this comment.
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"]')) { |
There was a problem hiding this comment.
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]>
|
/approve-spec b47eabe |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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.
…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.
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
role="status"and is born with its text, so whether it is spoken depends on the screen reader.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 helperuseAnnounceRenderedTextwithskipFirstRender. 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-runtimeINV10).Expected behavior and authority
spec:AST-086FR2, FR4, FR11, FR12 (current), andarchitecture:react-component-runtimeINV10 (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: norole="status"; the text group is wrapped inAnnounceRenderedText.hooks/AnnounceRenderedText.tsx(internal,'use client') andhooks/useAnnounceRenderedText.ts: theskipFirstRenderoption, page-load detection read when announcing, the hidden and live-container checks.serverSafeComponents.test.ts: admits the client island.EmptyState.spec.mdAR3,EmptyState.doc.mjsanatomy line, patch[fix]changeset.role="status", and ListInput's expectation of the joined same-frame announcement (FR9).Evidence
role="status"and mounts with its text.hiddenremoval while the document is still loading; once when it appears later; once when its message changes later; silent inside arole="log"; silent from a server render and its hydration; action labels and the icon are never spoken.Scope
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-clientclean.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 withoutcheckVisibility(Safari before 17.4) keep the previous behavior: there, such an EmptyState is announced when it appears even while hidden by CSS. AgetClientRects()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-086FR12, FR13).Co-authored-by: Harjoth Khara [email protected]