[Bug]: Manager crashes with LandmarkManager TypeError when the sidebar is shown while the toolbar is hidden
Describe the bug
With the toolbar hidden, bringing back a hidden sidebar crashes the manager UI:
TypeError: Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.
at LandmarkManager.addLandmark
at LandmarkManager.registerLandmarkToolbar (code/core/src/manager/components/preview/Toolbar.tsx) calls useLandmark unconditionally, but returns null when isShown is false. Its landmark stays registered with ref.current === null. When the sidebar remounts, addLandmark binary-searches the existing landmarks and calls compareDocumentPosition on that null node.
You can see it in the registry after pressing Alt+T:
document[Symbol.for('react-aria-landmark-manager')].landmarks
.map(l => `${l.label}: ${!!l.ref.current}`)
// [..., "sb-preview-toolbar-title: false", "main-preview-heading: true", ...]This is the same crash as #34711. #34790 fixed it for the mobile addon panel only, and the toolbar still hits it.
Reproduction link
https://storybook.new (a fresh react-vite project reproduces it with no changes)
Reproduction steps
- Open any story with the toolbar and sidebar visible.
- Press Alt+T to hide the toolbar.
- Press Alt+S to hide the sidebar.
- Press Cmd+K (Ctrl+K) to focus search. The search shortcut calls
toggleNav(true), the sidebar remounts, and the manager shows "Something went wrong".
We first hit it without step 2, because our layoutCustomisations.showToolbar hides the toolbar for some stories.
System
Storybook Environment Info:
System:
OS: macOS 26.4.1
CPU: (18) arm64 Apple M5 Pro
Binaries:
Node: 24.19.0
npm: 11.17.0
Browsers:
Chrome: 153.0.8010.54
npmPackages:
@storybook/addon-a11y: 10.6.0
@storybook/addon-docs: 10.6.0
@storybook/addon-mcp: 10.6.0
@storybook/addon-vitest: 10.6.0
@storybook/react-vite: 10.6.0
storybook: 10.6.0Additional context
Guarding useLandmark against a null ref, or only rendering the landmark hook while the toolbar is shown, should fix it. Any component that calls useLandmark and can return null has the same problem.
Source: storybookjs/storybook