Command Palette: Search result scroll jumps and layout jitters#77023
Command Palette: Search result scroll jumps and layout jitters#77023DarkMatter-999 wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @DarkMatter-999! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
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. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
What?
Closes #77021
This is a solution for current Command Palette, before when we move away from
cmdk, as mentioned here.Why?
This PR fixes a UI isssue in the Command Palette where the results list would unexpectedly scroll downward or "jitter" when filtering results.
The issue was caused by a conflict between cmdk’s internal scroll-into-view logic and the asynchronous nature of command loaders. When new results were injected or the search string changed, the library would attempt to center the active selection. If this happened while the DOM was still reconciling or the list height was shifting, it resulted in a "jump" that disoriented the user.
How?
To ensure a stable and "sticky" scroll position at the top of the list during filtering, added a
useLayoutEffecthook inCommandMenuthat targets the[cmdk-list]container. It synchronously resetsscrollTopto 0 whenever the search state orloadersLoadingstate changes.Because cmdk occasionally triggers its own scroll logic asynchronously (after the initial render), the reset logic uses an animation loop. This "guards" the scroll position for 10 frames (~160ms) to override any late-firing internal library scrolls.
Testing Instructions
Screenshots or screencast
Before
command-palette.mp4
After
command-palette-fix.mp4
Use of AI Tools
Gemini 3.1 Pro and Claude Sonnet 4.6 were used for research.