-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Addon Docs: Add __STORYBOOK_UNSAFE_TOCBOT__ global
#32176
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
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.
2 files reviewed, no comments
|
View your CI Pipeline Execution ↗ for commit 53e5d1d
☁️ Nx Cloud last updated this comment at |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 12 | 12 | 0 |
| Self size | 2.42 MB | 2.47 MB | 🚨 +53 KB 🚨 |
| Dependency size | 8.93 MB | 8.93 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
shilman
left a comment
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.
Thank you @yannbf !!!
__STORYBOOK_UNSAFE_TOCBOT__ option__STORYBOOK_UNSAFE_TOCBOT__ global
|
@yannbf please add a manual testing section so we can do QA |
|
Turns out this feature got removed. |
Closes ##31449
What I did
Previously, Storybook was using an older version of tocbot (4.23.0) and the package was being bundled as its CJS version, which by side effect, ended up exposing
tocboton the window object. Now, Storybook uses a newer version which is now bundled as its ESM version and therefore thattocbotis not exposed anymore.This PR introduces a way to re-acess the object via
globalThis.__STORYBOOK_UNSAFE_TOCBOT__(at your own risk) to allow usage the same way a before. This is an undocumented feature and shouldn't be used unless you know what you're doing, and it can change in between versions of Storybook.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH 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.tsMake 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/coreteam 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
This PR introduces the
__STORYBOOK_UNSAFE_TOCBOT__global variable to restore access to the tocbot instance that was lost when Storybook upgraded from tocbot 4.23.0 to a newer version. The change addresses a breaking issue where users who relied on the accidentally exposed tocbot instance (previously available due to CJS bundling side effects) to refresh table of contents for dynamically loaded content lost this functionality when Storybook switched to ESM bundling.The implementation adds a conditional assignment in
preview.tsthat exposes eithertocbot.defaultortocbotitself viaglobalThis.__STORYBOOK_UNSAFE_TOCBOT__, handling both CJS and ESM module formats. A corresponding TypeScript declaration is added totypings.d.tsto provide proper typing support. The "UNSAFE" naming convention clearly signals this is an undocumented escape hatch that may change between versions.This change fits into Storybook's addon architecture by providing backward compatibility while explicitly marking the API as unstable through its naming convention, allowing users to migrate their code while maintaining functionality.
PR Description Notes:
Confidence score: 4/5