Skip to content

Off-screen <Command /> mount can scroll the window unexpectedly #405

Description

@thevuong

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

  1. Render a long page.
  2. Place <Command> in a section far below the fold.
  3. Navigate to that page from another route while currently at scrollY = 0.
  4. 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.scrollIntoView
  • ne (.../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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions