Off-screen <Command /> mount can scroll the window unexpectedly
Author: thevuongCreated May 29, 2026Updated Jun 10, 2026
Describe the bug
Mounting cmdk's <Command /> off-screen can trigger Element.scrollIntoView() internally and unexpectedly scroll the page window to that off-screen location.
In our case, this happened even though no hash navigation was used and no explicit app-level scroll logic ran.
Reproduction steps
- Render a long page.
- Place
<Command>in a section far below the fold. - Navigate to that page from another route while currently at
scrollY = 0. - Observe that the page jumps down automatically near the
<Command>section.
Expected behavior
The page should stay at top (or keep router/browser restoration behavior), and Command internals should not force-window-scroll when mounted off-screen.
Actual behavior
Window scroll jumps down on mount.
Runtime evidence
When instrumenting Element.prototype.scrollIntoView, the call stack points to cmdk internals:
Element.scrollIntoViewne (.../cmdk.js:160:152).../cmdk.js:451:28
Environment
cmdk:1.1.1- React:
19.2.6 - Browser: Chromium (via Cursor embedded browser)
- Router: TanStack Router
Workaround
Delaying/lazy-mounting the off-screen <Command> section avoids the jump, which further suggests the mount-time scrollIntoView path is the trigger.
Source: dip/cmdk