-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon-Docs: Change URL hash when TOC item is clicked, and fix TOC loading bugs #30130
base: next
Are you sure you want to change the base?
Conversation
Co-authored-by: Norbert de Langen <ndelangen@me.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile
if (typeof to === 'string' && to.startsWith('#')) { | ||
document.location.hash = to; | ||
if (to === '#') { | ||
navigate(document.location.search); | ||
} else { | ||
document.location.hash = to; | ||
} | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: this new hash handling could cause issues if document.location.search is empty - consider falling back to '/' or preserving the current path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false positive, prior PR code
View your CI Pipeline Execution ↗ for commit f07cf4a.
☁️ Nx Cloud last updated this comment at |
3663df5
to
c9d5743
Compare
Note the failing unit tests on https://github.com/storybookjs/storybook/actions/runs/12474578164/job/34816789722?pr=30130.
|
Closes #26345.
Closes #29361.
Continuation of #23618.
This PR was done to help finalise a contribution from @sookmax. The original PR updated the URL when clicking on a ToC item or scrolling to a new ToC section.
What I did
I made the following changes to the original PR:
useEffect
hook dependencies were added in the ToC componentAs a result, the URL no longer updates when users scroll, and the page now correctly loads on the right docs subsection when loading Storybook with a location hash set.
Checklist for Contributors
Testing
Caution
The original PR did not introduce tests, and neither does this one. I'd like to be advised on how best to proceed. I've tried, without much conviction, to build a stories file but I'd need to mock the channel for this and I don't know how to.
The changes in this PR are covered in the following automated tests:
Manual testing
storybook:ui
Section IDs with a space need to be URL encoded. The ID generated in MDX already contains
%20
, so that needs to be encoded to%2520
to load properly.Note
If maintainers know where I can edit the behaviour that generates header IDs in the docs addon, I'll happily adjust it to use
_
instead of%20
to help keep URL hashes cleaner.Caution
The 🔗 links next to headings in the addon-doc also need to be URL encoded so we get the
%2520
link that will work with tocbot. I feel the better solution is to adjust all links to use_
rather than further mess with that code. Please let me know how you'd prefer me to proceed.Documentation
Note
I do not think documentation changes are relevant here.
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
Here's my concise review of the changes focused on fixing Table of Contents URL handling and navigation:
Updates Table of Contents functionality to properly handle URL hash navigation and preserve hash fragments across state changes, focusing on consistent URL behavior.
code/core/src/manager-api/modules/url.ts
for navigation events and state updatescode/lib/blocks/src/components/TableOfContents.tsx
by emitting proper NAVIGATE_URL eventsuseNavigate
hook incode/core/src/router/router.tsx
to handle empty hash navigation correctlycode/lib/blocks/src/blocks/DocsContainer.tsx
💡 (5/5) You can turn off certain types of comments like style here!