close
Skip to content

Command Palette: Search result scroll jumps and layout jitters#77023

Open
DarkMatter-999 wants to merge 1 commit intoWordPress:trunkfrom
DarkMatter-999:fix/command-pallete-sort-fix
Open

Command Palette: Search result scroll jumps and layout jitters#77023
DarkMatter-999 wants to merge 1 commit intoWordPress:trunkfrom
DarkMatter-999:fix/command-pallete-sort-fix

Conversation

@DarkMatter-999
Copy link
Copy Markdown

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 useLayoutEffect hook in CommandMenu that targets the [cmdk-list] container. It synchronously resets scrollTop to 0 whenever the search state or loadersLoading state 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

  1. Open the Command Palette (e.g., via Cmd+K)
  2. Type "t", the results updates, with selected result un the top.
  3. Type "a", so the search term becomes "ta", the search results stay in the view.
  4. Complete typing the whole search term, "tags."

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.

@github-actions github-actions bot added [Package] Commands /packages/commands First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository labels Apr 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

👋 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.

@DarkMatter-999 DarkMatter-999 marked this pull request as ready for review April 3, 2026 11:08
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: DarkMatter-999 <lakshyajeet@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

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.

  • Required label: Any label starting with [Type].
  • Labels found: First-time Contributor, [Package] Commands.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Commands /packages/commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command Palette: Search result scroll jumps and layout jitters

1 participant