Storybook Share Tool#
Overview#
The Storybook Share Tool encompasses two distinct capabilities in the manager toolbar: isolation mode (opening a story's preview in a new tab without the Storybook UI chrome) and cloud publishing (delegated to the Chromatic addon for one-click shareable links). The core codebase handles the isolation mode button and URL generation; authentication, error handling, and cloud publishing are delegated to third-party addons.
Entry Points#
| File | Purpose |
|---|---|
share.tsx | Defines isolationModeTool β the only built-in share-related toolbar component |
container/Preview.tsx | Registers isolationModeTool in defaultToolsExtra |
manager-api/modules/url.ts | getStoryHrefs() β URL generation API used by the isolation mode button |
core-events/index.ts | SHARE_ISOLATE_MODE = 'shareIsolateMode' β event emitted on isolation mode click |
checklistData.tsx | Onboarding checklist "Share" section with Chromatic-conditional items |
Isolation Mode Tool#
The isolationModeTool is an Addon_BaseType registered as types.TOOLEXTRA. It renders only in viewMode === 'story' without a tab active .
On click, it:
- Calls
api.getStoryHrefs(storyId, { base: 'origin', refId, inheritArgs: true })to generate the preview URL . - Opens the
previewHrefin a new tab viawindow.open(..., '_blank', 'noopener,noreferrer'). - Emits the
SHARE_ISOLATE_MODE('shareIsolateMode') event on the channel with the URL .
getStoryHrefs returns both a managerHref and a previewHref; the isolation mode tool specifically uses previewHref β the iframe-only URL without the Storybook chrome .
Cloud Publishing via Chromatic Addon#
Core Storybook does not implement cloud publishing itself. The onboarding checklist detects whether the Chromatic visual tests addon's share tool (chromaui/addon-visual-tests/share-tool) is registered, and branches accordingly :
-
Chromatic addon present β shows the
shareStorybookchecklist item. It tracks completion by listening forexperimental_useSharedState_setValueevents on thechromaui/addon-visual-tests/shareProgresskey. The action button triggersdocument.getElementById('chromatic-share-button')?.click()β delegating directly to the addon's DOM element . -
Chromatic addon absent β shows the
publishStorybookitem, which guides users to runnpx storybook buildand deploy to Chromatic, Vercel, or Netlify .
Addon detection uses addons.experimental_getRegisteredAddons(Addon_TypesEnum.TOOLEXTRA) . This approach means the core checklist has no knowledge of Chromatic's authentication flows, build state, or error handling β all of that lives within the Chromatic addon.
Delegation of Auth & Error Handling#
The share tool in core Storybook has no authentication UI or error handling of its own. This is intentional:
- Authentication: When Chromatic-hosted refs return 401 errors, the refs system extracts a
loginUrlfrom the response and surfaces a login prompt β handled in the refs module, not in the share tool. - Share progress & errors: The Chromatic addon writes progress state to shared state under
chromaui/addon-visual-tests/shareProgress. Core Storybook only reads this key to mark the checklist item complete whenstatus === 'complete'. Any error states from the Chromatic addon are displayed by the Chromatic addon's own UI.
QR Code Infrastructure (Removed from Toolbar)#
An earlier version of the share tool included QR code generation (using qrcode.react) and a copy-to-clipboard share link popover. PR #34413 redesigned the share tool and removed the QR code feature from the toolbar to reduce clutter . The QRCodeSVG import and styled components (QRContainer, QRRow, QRImageContainer, etc.) remain in share.tsx but are currently unused by the exported isolationModeTool.
References#
- Chromatic sharing docs β external reference for the Chromatic share flow
- Storybook publish docs β official guide for static deployment