Repository navigation
Conversation
The built-in announcements for SelectPanel fired after every single keystroke while filtering, queueing up a burst of duplicate screen reader messages. Debounce the list-update announcements (250ms, same pattern and window as AutocompleteMenu's debounceAnnouncement) so only the latest state is announced once typing pauses. Focus announcements still fire immediately, and any pending announcement is cancelled on unmount. Fixes primer#7611
🦋 Changeset detectedLatest commit: 55e5292 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
StrictMode cleanup permanently disables the memoized debouncer, silently dropping later list-update announcements, while stale empty-result messages can still be announced after a new query starts.
3 open issues
What changed in this PR
Reduces repeated screen reader messages while filtering SelectPanel and FilteredActionList, addressing #7611.
Changes:
- Adds a 250ms debounce for list-update announcements and cleanup on unmount.
- Leaves focus announcements unchanged and adds rapid-filter test coverage.
- Records the change in an
@primer/reactpatch changeset.
| File | Description |
|---|---|
packages/react/src/FilteredActionList/useAnnouncements.tsx |
Adds debounced list-update announcements and cleanup. |
packages/react/src/FilteredActionList/useAnnouncements.test.tsx |
Adds a rapid-filter announcement test. |
.changeset/select-panel-announcement-debounce.md |
Documents the accessibility fix for release. |
Review effort: Max
Copilot review on primer#8769: cancel() in @github/mini-throttle permanently disables the debouncer, so the memoized instance was disabled by StrictMode's cleanup replay on mount and every later list-update announcement was silently dropped. A queued empty-result message could also be announced after a new query started loading. Hold the debouncer in a ref and (re)create it lazily: each state change cancels the pending announcement and discards the cancelled instance, so the next schedule gets a fresh one. Cancelling happens in the effect body on state change (including transitions that schedule no replacement); unmount cancels via a separate effect whose cleanup only runs on unmount. Pending announcements survive unrelated re-renders, as before. Tests: rewrite the debounce test with fake timers (spaced updates, varying payloads, assert silence before the deadline and exactly one call with the final text), add a StrictMode regression test and a stale empty-result test.
|
Integration test results from github/github-ui PR:
All checks passed! |
Comment on lines
+111
to
+128
| const debouncedAnnounceRef = useRef<DebouncedAnnounce | null>(null) | ||
|
|
||
| // Drop the current debouncer, cancelling any pending announcement. | ||
| const cancelPendingAnnouncement = useCallback(() => { | ||
| debouncedAnnounceRef.current?.cancel() | ||
| debouncedAnnounceRef.current = null | ||
| }, []) | ||
|
|
||
| const getDebouncedAnnounce = useCallback((): DebouncedAnnounce => { | ||
| let debounced = debouncedAnnounceRef.current | ||
| if (!debounced) { | ||
| debounced = debounce((text: string, options?: Parameters<typeof liveRegionAnnounce>[1]) => { | ||
| announce(text, options) | ||
| }, 250) | ||
| debouncedAnnounceRef.current = debounced | ||
| } | ||
| return debounced | ||
| }, [announce]) |
Comment on lines
+130
to
+134
| // Cancel any pending announcement on unmount so nothing is announced | ||
| // after the component is gone. This effect's cleanup only runs on | ||
| // unmount (and on StrictMode's mount replay, where nothing is pending | ||
| // yet), so it never cancels announcements for a live component. | ||
| useEffect(() => cancelPendingAnnouncement, [cancelPendingAnnouncement]) |
| ].join(', ') | ||
|
|
||
| announce(announcementText, { | ||
| debouncedAnnounce(announcementText, { |
| ].join(', ') | ||
|
|
||
| announce(announcementText, { | ||
| debouncedAnnounce(announcementText, { |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #7611
The built-in announcements for SelectPanel fire after every single keystroke while filtering, queueing up a burst of duplicate screen reader messages.
Changelog
Changed
useAnnouncements(used by SelectPanel / FilteredActionList) are now debounced by 250ms, so only the latest state is announced once typing pauses. Focus announcements still fire immediately, and any pending announcement is cancelled on unmount.Rollout strategy
Testing & Reviewing
debounces list update announcements while the filter value changes rapidly) that changes the filter value three times in quick succession and asserts only one announcement is made, with the latest text.npx vitest run packages/react/src/FilteredActionList/useAnnouncements.test.tsx: all 6 tests pass, including the 5 pre-existing ones.AutocompleteMenu'sdebounceAnnouncement, same@github/mini-throttledebounceand 250ms window).Thank you for taking a look — happy to adjust the debounce window or approach if you would prefer a different one.