Commands: Fix useSelect warning in command palette#76822
Conversation
Move the `?? []` fallback outside of `useSelect` to avoid creating a new array reference on every call when the preference is undefined. Use a module-level `EMPTY_ARRAY` constant as a stable default instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
useSelect return value for recentlyUsedNames|
Size Change: +8 B (0%) Total Size: 7.69 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 174ad64. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23584418957
|
…s` (#76822) Move the `?? []` fallback outside of `useSelect` to avoid creating a new array reference on every call when the preference is undefined. Use a module-level `EMPTY_ARRAY` constant as a stable default instead. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Follow-up on #75691
What?
Fix the browser console warning that appears when opening the command palette:
Why?
The
?? []fallback insideuseSelectcreates a new empty array reference on every call when therecentlyUsedpreference isundefined. This causesuseSelect's shallow equality check to fail, triggering unnecessary re-renders and the warning above.How?
useSelectby using a module-levelEMPTY_ARRAYconstant as a stable default value in the destructuring assignment.Testing Instructions
First, execute the following code in the browser console.
Use of AI Tools
This PR was authored with assistance from Claude Code (Claude Opus 4.6).