Repository navigation
fix(PowerSearch): the result count is announced once under StrictMode - #8650
Conversation
…r StrictMode The result-count live-region effect skipped its first run with a mounted flag. React StrictMode replays mount effects, resetting the flag, so the count present on mount was announced unprompted. The guard now compares against the last announced text, so only a change after mount is spoken in every render mode. The popover presentation's StrictMode test fails on main and passes here.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsPowerSearch (@astryxdesign/core) · View in Storybook
Component Size
Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included. Bundle Size SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. PowerSearch - 1 issue(s)
Visual Regression55 of 504 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 35 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Recommended for approval: comparing the count's text with the last text the Effect saw keeps PowerSearch silent about the count already on screen when it mounts under React StrictMode, a later change is still announced once, and the new StrictMode test fails against the old guard and passes with this change. One optional fix: the Changeset, which becomes the release note, and the comments in PowerSearch.tsx and PowerSearch.test.tsx say StrictMode's replay "resets" the mounted flag, but the flag survives the replay, which is why the old guard announced. StrictMode's effect replay only runs in development builds, so the description's mention of StrictMode-enabled production trees overstates where the symptom appeared. Also worth knowing, and consistent with the documented contract: the same guard keeps an unchanged count silent when an <Activity> boundary reveals the field, and announces a count that changed during a hidden <Activity> pre-render once, at its first reveal.
[Automated review]
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] PowerSearch no longer announces its initial `resultCount` on mount under React StrictMode. The result-count live-region effect guarded its first run with a mounted flag that StrictMode's effect replay reset, so the count present on mount was spoken unprompted; the guard now compares against the last announced text, so only a change after mount is announced in every render mode. |
There was a problem hiding this comment.
The mechanism clause is inverted: StrictMode's effect replay keeps hasMountedRef set (refs survive the simulated remount), which is why the replayed first run announced the mount count. Suggested wording: "…guarded its first run with a mounted flag that survives StrictMode's effect replay, so the count present on mount was spoken unprompted…". The same "reset" wording is in the comments at packages/core/src/PowerSearch/PowerSearch.tsx:1062 and packages/core/src/PowerSearch/PowerSearch.test.tsx:480-481.
fix(core): PowerSearch does not announce its initial
resultCountunder StrictModeUser impact
Anyone using a screen reader on an app that renders
PowerSearchwith aresultCountunder ReactStrictMode(the default in Next.js and Create React App development, and in any app that opts in). On mount, the field spoke the count already on screen — "12 results" — unprompted, before the person touched the field. The count is meant to be heard only when it changes after mount; the first render is silent. Outside StrictMode the behavior is as documented, so the defect shows in development and in StrictMode-enabled production trees, and it hits every mount: a page with three PowerSearch fields announces three counts on load. Restoring it makes the first render silent in every render mode and keeps the change-driven announcement intact.Problem and solution fit
Why does the defect occur? The result-count effect skipped its first run with a mounted flag (
hasMountedRef): the first effect run set the flag and returned, later runs announced. StrictMode mounts, unmounts and remounts a component in development and replays its effects; the ref keeps its value across the replay, so the replayed first run sees the flag already set and announces the initial count.Why does it harm the task? A live-region announcement interrupts whatever the screen reader was reading. On load that is usually the page heading or the field the person is moving to; an unrequested "12 results" is noise with no action attached, and with several fields it is several interruptions.
Why does that harm matter? The field's own contract says the count is spoken only when it changes after mount (
component:PowerSearchFR19), and that promise is what lets a product put aresultCounton every search field without an accessibility cost on load. A guard that holds in one render mode and not in another makes the promise depend on how the app is wrapped.The narrow fix drops the mounted flag and compares against the last announced text instead: the ref starts as the mount's count, so the first run — replayed or not — has nothing new to say, and a later change is announced once. Nothing else in the effect changes.
Expected behavior and authority
component:PowerSearchFR19 (packages/core/src/PowerSearch/PowerSearch.spec.md, current): the result count "is announced only when it changes after mount; the first render announces nothing, including under StrictMode's effect replay."[fix]outside the experimental exception, qualifying underspec:AST-017/FR5: it restores the documented contract, changes noonChangevalue, prop or rendered text, and asks no valid consumer to change..changeset/powersearch-result-count-strictmode.md:[fix]patch for@astryxdesign/core.Smallest restoration
One guard in
PowerSearch.tsx:announcedResultCountRefinitialized to the mount'sresultCountText; the effect returns when the text equals the ref, otherwise records it and announces when non-null. The mounted flag is gone. The effect's dependencies, the visual count, the live-region channel and the singular/plural text are untouched; no prop, default, visual or interaction changes. The comment above the effect now explains the StrictMode case.Evidence
PowerSearch.test.tsx› "does not announce the result count present on mount under StrictMode, only a later change" onmain(f3a9d8c39), run with the test alone cherry-picked: fails withAssertionError: expected '12 results' to be ''— the polite region holds the mount count 20 ms after render.resultCountchanges from 12 to 1 it reads "1 result".resultCountrendering tests pass unchanged, so a change after mount is still spoken once and the visible count is as before, outside StrictMode.<StrictMode>, asserts an empty polite region after mount, then asserts the announcement after a change. Reverting the guard to the mounted flag fails it (above); removing the announcement altogether fails its second assertion.Scope
Testing
pnpm exec vitest run packages/core/src/PowerSearch— 9 files, 256 tests pass (the new StrictMode test included).pnpm -F @astryxdesign/core typecheckandtypecheck:docs— exit 0.no-nullish-jsx-guardwarning on the count's JSX, not touched here).git diff --checkclean.