-
-
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
Conversation
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
View your CI Pipeline Execution ↗ for commit 0017926.
☁️ 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.
|
Let's try to improve the slugs of heading's IDs, turning spaces into dashes to avoid |
f07cf4a
to
51f4b60
Compare
Turns out the block responsible for those headings was not yet using slugs. I've used Will now wait for CI to run and then address the failing tests. |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
Before | After | Difference | |
---|---|---|---|
Dependency count | 13 | 13 | 0 |
Self size | 2.26 MB | 2.24 MB | 🎉 -16 KB 🎉 |
Dependency size | 9.41 MB | 9.43 MB | 🚨 +19 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/addon-essentials
Before | After | Difference | |
---|---|---|---|
Dependency count | 32 | 32 | 0 |
Self size | 12 KB | 12 KB | 0 B |
Dependency size | 15.43 MB | 15.44 MB | 🚨 +11 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/blocks
Before | After | Difference | |
---|---|---|---|
Dependency count | 2 | 2 | 0 |
Self size | 607 KB | 626 KB | 🚨 +19 KB 🚨 |
Dependency size | 1.28 MB | 1.28 MB | 0 B |
Bundle Size Analyzer | Link | Link |
@JReinhold CI now passing, this should be ready for review :) |
Co-authored-by: Norbert de Langen <[email protected]>
c1b9a94
to
8cc7f4a
Compare
@JReinhold would you have some time this week to review this PR? I'd love to see it go online as there were a few other issues mentioning problems with heading links, we've got a new tocbot release fixing up some of the issues with current heading highlighting and now #30411. It could be nice to bundle these changes together so they can be announced in a next minor release. I'll do a first review of #30411 myself. |
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.
Great work!
When I'm trying it out, it seems to (almost) work as it should:
- clicking a heading-link and reloading takes me back to the heading
- clicking a link in the toc and reloading also takes me back to the heading
However there appears to be a problem with Unicode. If you look at the docs for the Unicode stories: http://localhost:6006/?path=/docs/%F0%9F%98%80--docs
Clinking the headings and reloading works fine, however clicking the toc and reloading does not. They also generate different hashes:
- heading link:
%EB%B0%94%EB%B3%B4
-바보
decoded - toc link:
%25EB%25B0%2594%25EB%25B3%25B4
-%EB%B0%94%EB%B3%B4
decoded
code/lib/blocks/package.json
Outdated
@@ -45,6 +45,7 @@ | |||
"dependencies": { | |||
"@storybook/csf": "0.1.12", | |||
"@storybook/icons": "^1.2.12", | |||
"github-slugger": "^2.0.0", |
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.
I've made this a devDependency
. We do that with all dependencies where possible, so they are prebundled, which greatly reduces Storybook's install-size.
I think I've fixed the unicode problem with my commit, and couldn't get the behavior to crash. Would be great if you could try it out too. |
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.
From my POV this is good to go, but I'm unsure if there is more stuff you want to do here @Sidnioulz? I'm slightly confused about the PR description 😅
Thanks for the review @JReinhold! I had forgotten to remove the instance of URL encoding that your commit removed, after applying passing heading IDs through GitHub Slugger. I checked and also conclude that reloading works in the example you showcase, regardless of whether I clicked in tocbot or not. I'm happy to merge as-is if this meets your standards, I just regret that I don't have dedicated tests for the navigation logic as I feel there should be some that cover hashes, search params, etc. WDYT? |
I dont think it's feasible to test this properly in a unit test or a story, simply too many moving parts. I think this is a case where the ROI on a test for this is not there. If you want to take a go at an E2E test I wont stop you, but I'd say merge this now and if we find out that this regress more than we thought, we can write a test for it then. |
Alright, happy to have it merged then! Errata: I realise the Heading component hasn't been updated, only Subheading! I've added a commit to update Heading. |
Closes #26345.
Closes #29361.
Closes #25632.
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!