Skip to content

fix(PowerSearch): the result count is announced once under StrictMode - #8650

Merged
imdreamrunner merged 1 commit into
mainfrom
fix/powersearch-result-count-strictmode
Oct 27, 2026
Merged

imdreamrunner merged 1 commit into
mainfrom
fix/powersearch-result-count-strictmode

Conversation

@imdreamrunner

Copy link
Copy Markdown
Contributor

fix(core): PowerSearch does not announce its initial resultCount under StrictMode

User impact

Anyone using a screen reader on an app that renders PowerSearch with a resultCount under React StrictMode (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:PowerSearch FR19), and that promise is what lets a product put a resultCount on 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:PowerSearch FR19 (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."
  • The record's Compatibility section names this change as a stable [fix] outside the experimental exception, qualifying under spec:AST-017/FR5: it restores the documented contract, changes no onChange value, 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: announcedResultCountRef initialized to the mount's resultCountText; 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

  • Reproduction before the change: PowerSearch.test.tsx › "does not announce the result count present on mount under StrictMode, only a later change" on main (f3a9d8c39), run with the test alone cherry-picked: fails with AssertionError: expected '12 results' to be '' — the polite region holds the mount count 20 ms after render.
  • Result after the change: the same test passes — the region is empty after mount, and after resultCount changes from 12 to 1 it reads "1 result".
  • Representative unchanged path: the existing "announces the result count to a polite live region when it changes" (0 → 5, "5 results"), "announces '1 result' (singular) for a single match" and the resultCount rendering tests pass unchanged, so a change after mount is still spoken once and the visible count is as before, outside StrictMode.
  • Regression test or other mutation-sensitive proof: the new test renders inside <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

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split: this change is extracted from the experimental sheet-presentation pull request so the stable fix ships on its own, as the record says it does.
  • 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 exec vitest run packages/core/src/PowerSearch — 9 files, 256 tests pass (the new StrictMode test included).
  • pnpm -F @astryxdesign/core typecheck and typecheck:docs — exit 0.
  • Strict lint on the two touched files: no new findings (one pre-existing no-nullish-jsx-guard warning on the count's JSX, not touched here).
  • Prettier clean; git diff --check clean.
  • No real-browser state depends on this change: the live region is text in the DOM, asserted directly by the tests.

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

vercel Bot commented Oct 27, 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 27, 2026 4:57am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 27, 2026, 4:49 PM UTC

@github-actions

github-actions Bot commented Oct 27, 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

PowerSearch (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Entry File (ESM) 640B 640B 0B
Lines of Code 3948 3948 -
Complexity Very High Very High (348) -

Component Size

Component Import before Import after Delta CSS before CSS after Delta
core/PowerSearch 155.1KB 155.1KB -2B 18.6KB 18.6KB 0B

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 Summary

Gzip figures measure each package's entry file, not the code an import pulls in.

Package Entry (ESM) Entry gzip before Entry gzip after Delta
@astryxdesign/core 4.9KB 1.2KB 1.2KB 0B
Package stylesheet Gzip before Gzip after Delta
@astryxdesign/core 34.6KB 34.6KB 0B

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

PowerSearch - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/31 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

55 of 504 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
RichTextEditor Markdown parity: side by side probe dark 558,840
RichTextEditor Markdown parity: side by side probe light 540,756
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
AppShell With Mobile Nav probe light 217,010
AppShell With Mobile Nav probe dark 216,960
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
AppShell Playground neutral dark 65,198
AppShell Playground neutral light 63,788
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

and 35 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.

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.

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.

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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 27, 2026
@imdreamrunner
imdreamrunner merged commit cf17cf2 into main Oct 27, 2026
73 checks passed
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 27, 2026
…eta#8297, meta#8650, meta#8672) into meta#8203

# Conflicts:
#	packages/core/src/BottomSheet/BottomSheet.tsx
@github-actions
github-actions Bot deleted the fix/powersearch-result-count-strictmode branch October 28, 2026 06:17

This branch was successfully deployed

1 active deployment
Preview — 8628307c Deployed Oct 27, 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