storybook/docs/addons/addon-migration-guide.md
2024-02-16 14:20:08 +01:00

6.2 KiB
Raw Blame History

title
Addon migration guide for Storybook 8.0

We deeply appreciate the dedication and effort addon creators put into keeping the Storybook ecosystem vibrant and up-to-date. As Storybook evolves to version 8.0, bringing new features and improvements, this guide is here to assist you in migrating your addons from 7.x to 8.0. If you need to migrate your addon from an earlier version of Storybook, please first refer to the Addon migration guide for Storybook 7.0.

As we gather feedback from the community, well update this page. We also have a general Storybook migration guide if youre looking for that.

Updating dependencies

Begin by updating your Storybook dependencies. Use the next tag for pre-release versions, latest for the most recent stable release, or specify the version directly.

{
  "dependencies": {
    "@storybook/client-logger": "next" // or "latest", or "^8.0.0"
  }
}

Key changes for addons

Here are the essential changes in version 8.0 that impact addon development. Please check the full migration note for an exhaustive list of changes in 8.0.

Node.js 16 support dropped

Please upgrade your addon to Node.js 18, as support for Node.js 16 has ended.

React 18 for manager UI

UI injected into panels, tools, etc. by addons is now rendered with React 18. Also note that the key prop is no longer passed to the render function.

React peer dependency is no longer required

To remove your addon's peer dependency on React, and reduce its install size, do the following:

  1. Move react, react-dom and the globalized Storybook packages from peerDependencies to devDependencies
  2. Add the list of globalized packages to the externals property in the tsup configuration, to ensure they are not part of the bundle.

For an example, see the updates we've made to the addon-kit. These changes are optional but recommended.

Note: This assumes your addon is using tsup for bundling. If your addon was built with an older version of addon-kit that uses Babel for bundling, you have to first switch to tsup. For guidance, explore these older changes implemented in the addon-kit.

@storybook/components deprecations

Icons component from @storybook/components is now deprecated in favor of @storybook/icons. Additionally, various Button component props are also deprecated, with alternatives provided.

Storybook layout state API changes

If you're customizing the Storybook UI configuration with addons.setConfig({...}), be aware of the changes to the layout state API.

Removal of deprecated features

Deprecated packages and APIs from 7.0 are now removed in 8.0.Consult the full migration notes for details. Most notably for addons, the removal of the @storybook/addons now necessitates a switch to @storybook/preview-api and @storybook/manager-api.

Babel-loader removed from webpack

Storybook 8 removes babel-loader from the webpack5 builder. If your addon's preset overrides the babel() method, it will break if your users are using SWC to compile their files (which is the new default for Webpack 5-based Storybook projects).

To solve for both Babel and SWC, the most robust approach is to create an unplugin that will work with both Webpack and Vite builders. That will give you full control to run Babel (or whatever you want) on stories and components as they are loaded.

As a workaround, update your documentation to tell users to opt-in to Babel support. This should fix your addon in their project, at the cost of performance:

npx storybook@latest add @storybook/addon-webpack5-compiler-babel

Migration Example

The Addon Kit repository has been migrated to support Storybook 8.0, and you can use that as a real-world example to guide your migration. The migration incorporates most of the changes listed above, including migrating the package to ESM with type: module. Migrating to ESM is not necessary but we recommend it as it simplifes some of the setup. If you follow the ESM migration below and update your export map in package.json, you can safely remove any manager.js, preview.js and preset.js files from the root directory.

This complete diff view shows everything changed between 7.0 and 8.0, but not all of it is relevant for your migration. You can specifically focus on:

Releasing

Release a new major version of your addon for Storybook 8.0. We recommend you to continue supporting 7.x with minor or patch versions. We also recommend releasing your own addon using the next tag to test it out in projects.

Support

If you're still having issues with your addon after following this guide, please open a new discussion in our GitHub repository.