Skip to content

Commit

Permalink
Merge pull request #22856 from storybookjs/chore_vet_outdated_refs_docs
Browse files Browse the repository at this point in the history
Chore: (Docs) Removes references to outdated APIs and packages
(cherry picked from commit 1c3d369)
  • Loading branch information
jonniebigodes authored and kasperpeulen committed Jun 14, 2023
1 parent 7e80bbd commit 7a44840
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,111 @@ You can get the same result by setting [the parameter `parameters.docs.source.fo
### 7.0 Addon authors changes
#### New Addons API
Storybook 7 adds 2 new packages for addon authors to use: `@storybook/preview-api` and `@storybook/manager-api`.
These 2 packages replace `@storybook/addons`.
When adding addons to storybook, you can (for example) add panels:
```js
import { addons } from '@storybook/manager-api';

addons.addPanel('my-panel', {
title: 'My Panel',
render: ({ active, key }) => <div>My Panel</div>,
});
```
Note that this before would import `addons` from `@storybook/addons`, but now it imports `{ addons }` from `@storybook/manager-api`.
The `addons` export is now a named export only, there's no default export anymore, so make sure to update this usage.
The package `@storybook/addons` is still available, but it's only for backwards compatibility. It's not recommended to use it anymore.
It's also been used by addon creators to gain access to a few APIs like `makeDecorator`.
These APIs are now available in `@storybook/preview-api`.
Storybook users have had access to a few storybook-lifecycle hooks such as `useChannel`, `useParameter`, `useStorybookState`;
when these hooks are used in panels, they should be imported from `@storybook/manager-api`.
When these hooks are used in decorators/stories, they should be imported from `@storybook/preview-api`.
Storybook 7 includes `@storybook/addons` shim package that provides the old API and calls the new API under the hood.
This backwards compatibility will be removed in a future release of storybook.
Here's an example of using the new API:
The `@storybook/preview-api` is used here, because the `useEffect` hook is used in a decorator.
```js
import { useEffect, makeDecorator } from '@storybook/preview-api';

export const withMyAddon = makeDecorator({
name: 'withMyAddon',
parameterName: 'myAddon',
wrapper: (getStory) => {
useEffect(() => {
// do something with the options
}, []);
return getStory(context);
},
});
```
##### Specific instructions for addon creators
If you're an addon creator, you'll have to update your addon to use the new APIs.
That means you'll have to release a breaking release of your addon to make it compatible with Storybook 7.
It should no longer depend on `@storybook/addons`, but instead on `@storybook/preview-api` and/or `@storybook/manager-api`.
You might also depend (and use) these packages in your addon's decorators: `@storybook/store`, `@storybook/preview-web`, `@storybook/core-client`, `@storybook/client-api`; these have all been consolidated into `@storybook/preview-api`.
So if you use any of these packages, please import what you need from `@storybook/preview-api` instead.
Storybook 7 will prepare manager-code for the browser using ESbuild (before it was using a combination of webpack + babel).
This is a very important change, though it will not affect most addons.
It means that when creating custom addons, particularly custom addons within the repo in which they are consumed,
you will need to be aware that this code is not passed though babel, and thus will not use your babel config.
This can result in errors if you are using experimental JS features in your addon code, not supported yet by ESbuild,
or using babel dependent features such as Component selectors in Emotion.
ESbuild also places some constraints on things you can import into your addon's manager code: only woff2 files are supported, and not all image file types are supported.
Here's the [list](https://github.com/storybookjs/storybook/blob/next/code/builders/builder-manager/src/index.ts#L53-L70) of supported file types.
This is not configurable.
If this is a problem for your addon, you need to pre-compile your addon's manager code to ensure it works.
If you addon also introduces preview code (such a decorators) it will be passed though whatever builder + config the user has configured for their project; this hasn't changed.
In both the preview and manager code it's good to remember [Storybook now targets modern browser only](#modern-browser-support).
The package `@storybook/components` contain a lot of components useful for building addons.
Some of these addons have been moved to a new package `@storybook/blocks`.
These components were moved: `ColorControl`, `ColorPalette`, `ArgsTable`, `ArgRow`, `TabbedArgsTable`, `SectionRow`, `Source`, `Code`.
##### Specific instructions for addon users
All of storybook's core addons have been updated and are ready to use with Storybook 7.
We're working with the community to update the most popular addons.
But if you're using an addon that hasn't been updated yet, it might not work.
It's possible for example for older addons to use APIs that are no longer available in Storybook 7.
Your addon might not show upside of the storybook (manager) UI, or storybook might fail to start entirely.
When this happens to you please open an issue on the addon's repo, and ask the addon author to update their addon to be compatible with Storybook 7.
It's also useful for the storybook team to know which addons are not yet compatible, so please open an issue on the storybook repo as well; particularly if the addon is popular and causes a critical failure.
Here's a list of popular addons that are known not to be compatible with Storybook 7 yet:
- [ ] [storybook-addon-jsx](https://github.com/storybookjs/addon-jsx)
- [ ] [storybook-addon-dark-mode](https://github.com/hipstersmoothie/storybook-dark-mode)
Though storybook should de-duplicate storybook packages, storybook CLI's `upgrade` command will warn you when you have multiple storybook-dependencies, because it is a possibility that this causes addons/storybook to not work, so when running into issues, please run this:
```
npx sb upgrade
```
#### register.js removed
In SB 6.x and earlier, addons exported a `register.js` entry point by convention, and users would import this in `.storybook/manager.js`. This was [deprecated in SB 6.5](#deprecated-registerjs)
Expand Down

0 comments on commit 7a44840

Please sign in to comment.