storybook: [Bug]: URL with Hash ('#') in Storybook Do Not Scroll to Correct Position (ID Name)
Describe the bug
URLs with hashes (‘#’) and fragment IDs that lead to elements with id attributes do not scroll to the correct position when opening a fresh Storybook page from such URLs.
To Reproduce
- Go to a Storybook page of sufficient height, get the URL of an anchor.
- Create a new tab, paste the URL, and enter it into the search bar.
- Notice that the linked ID is not in view and that the viewport is too high on the page.
System
Storybook Environment Info:
System:
OS: macOS 14.2.1
CPU: (12) arm64 Apple M2 Pro
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm <----- active
Browsers:
Chrome: 120.0.6099.234
Safari: 17.2.1
npmPackages:
@storybook/addon-actions: 7.5.3 => 7.5.3
@storybook/addon-docs: 7.5.3 => 7.5.3
@storybook/addon-essentials: 7.5.3 => 7.5.3
@storybook/addon-interactions: 7.5.3 => 7.5.3
@storybook/addon-links: 7.5.3 => 7.5.3
@storybook/addons: 7.5.3 => 7.5.3
@storybook/blocks: 7.5.3 => 7.5.3
@storybook/builder-vite: 7.5.3 => 7.5.3
@storybook/react: 7.5.3 => 7.5.3
@storybook/react-vite: 7.5.3 => 7.5.3
eslint-plugin-storybook: 0.6.15 => 0.6.15
storybook: 7.5.3 => 7.5.3
Additional context
Nuances:
- This also occurs on the Storybook documentation site itself. It could be the same issue.
- This issue does not occur for IDs that are in the initial viewport. Take this page for example (of the Storybook doc’s site):
- https://storybook.js.org/docs/writing-stories/args
- If you go to the first ID (in view upon initial load), scroll is successful: https://storybook.js.org/docs/writing-stories/args#args-object
- If you go to the last ID (not in view upon initial load), scroll fails and ends too high on the page: https://storybook.js.org/docs/writing-stories/args#mapping-to-complex-arg-values
- This happens in a private Storybook as well.
- (edit - added 11/18😃 If you go to the last IDs link in a new tab without traveling to that browser tab (until the page has loaded by waiting a few seconds), the page will scroll to the correct position.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 22 (2 by maintainers)
I confirm. I have the same problem on version 8.3.3 of the storybook.
Having the same error on v7
The documentation website portion of this has been fixed!
I updated the labels once more to reflect that.
Having the same problem on Storybook v7…