Migration

- [From version 6.5.x to 7.0.0](#from-version-65x-to-700) - [Alpha release notes](#alpha-release-notes) - [7.0 breaking changes](#70-breaking-changes) - [removed auto injection of @storybook/addon-actions decorator](#removed-auto-injection-of-storybookaddon-actions-decorator) - [register.js removed](#registerjs-removed) - [Change of root html IDs](#change-of-root-html-ids) - [No more default export from `@storybook/addons`](#no-more-default-export-from-storybookaddons) - [Modern browser support](#modern-browser-support) - [No more configuration for manager](#no-more-configuration-for-manager) - [start-storybook / build-storybook binaries removed](#start-storybook--build-storybook-binaries-removed) - [storyStoreV7 enabled by default](#storystorev7-enabled-by-default) - [Webpack4 support discontinued](#webpack4-support-discontinued) - [Modern ESM / IE11 support discontinued](#modern-esm--ie11-support-discontinued) - [Framework field mandatory](#framework-field-mandatory) - [frameworkOptions renamed](#frameworkoptions-renamed) - [Framework standalone build moved](#framework-standalone-build-moved) - [Docs modern inline rendering by default](#docs-modern-inline-rendering-by-default) - [Babel mode v7 by default](#babel-mode-v7-by-default) - [7.0 feature flags removed](#70-feature-flags-removed) - [CLI option `--use-npm` deprecated](#cli-option---use-npm-deprecated) - [Vite builder uses vite config automatically](#vite-builder-uses-vite-config-automatically) - [Vite cache moved to node_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook) - [Removed docs.getContainer and getPage parameters](#removed-docsgetcontainer-and-getpage-parameters) - [Removed STORYBOOK_REACT_CLASSES global](#removed-storybook_react_classes-global) - [Icons API changed](#icons-api-changed) - ['config' preset entry replaced with 'previewAnnotations'](#config-preset-entry-replaced-with-previewannotations) - [Dropped support for Angular 12 and below](#dropped-support-for-angular-12-and-below) - [Addon-backgrounds: Removed deprecated grid parameter](#addon-backgrounds-removed-deprecated-grid-parameter) - [Addon-docs: Removed deprecated blocks.js entry](#addon-docs-removed-deprecated-blocksjs-entry) - [Addon-a11y: Removed deprecated withA11y decorator](#addon-a11y-removed-deprecated-witha11y-decorator) - [Docs Changes](#docs-changes) - [Standalone docs files](#standalone-docs-files) - [Referencing stories in docs files](#referencing-stories-in-docs-files) - [Docs Page](#docs-page) - [Configuring the Docs Container](#configuring-the-docs-container) - [External Docs](#external-docs) - [MDX2 upgrade](#mdx2-upgrade) - [Dropped source loader / storiesOf static snippets](#dropped-source-loader--storiesof-static-snippets) - [Dropped addon-docs manual configuration](#dropped-addon-docs-manual-configuration) - [Autoplay in docs](#autoplay-in-docs) - [7.0 Deprecations](#70-deprecations) - [`Story` type deprecated](#story-type-deprecated) - [`ComponentStory`, `ComponentStoryObj`, `ComponentStoryFn` and `ComponentMeta` types are deprecated](#componentstory-componentstoryobj-componentstoryfn-and-componentmeta-types-are-deprecated) - [Renamed `renderToDOM` to `renderToCanvas`](#renamed-rendertodom-to-rendertocanvas) - [Renamed `XFramework` to `XRenderer`](#renamed-xframework-to-xrenderer) - [Renamed `DecoratorFn` to `Decorator`](#renamed-decoratorfn-to-decorator) - [From version 6.4.x to 6.5.0](#from-version-64x-to-650) - [Vue 3 upgrade](#vue-3-upgrade) - [React18 new root API](#react18-new-root-api) - [Renamed isToolshown to showToolbar](#renamed-istoolshown-to-showtoolbar) - [Dropped support for addon-actions addDecorators](#dropped-support-for-addon-actions-adddecorators) - [Vite builder renamed](#vite-builder-renamed) - [Docs framework refactor for React](#docs-framework-refactor-for-react) - [Opt-in MDX2 support](#opt-in-mdx2-support) - [CSF3 auto-title improvements](#csf3-auto-title-improvements) - [Auto-title filename case](#auto-title-filename-case) - [Auto-title redundant filename](#auto-title-redundant-filename) - [Auto-title always prefixes](#auto-title-always-prefixes) - [6.5 Deprecations](#65-deprecations) - [Deprecated register.js](#deprecated-registerjs) - [From version 6.3.x to 6.4.0](#from-version-63x-to-640) - [Automigrate](#automigrate) - [CRA5 upgrade](#cra5-upgrade) - [CSF3 enabled](#csf3-enabled) - [Optional titles](#optional-titles) - [String literal titles](#string-literal-titles) - [StoryObj type](#storyobj-type) - [Story Store v7](#story-store-v7) - [Behavioral differences](#behavioral-differences) - [Main.js framework field](#mainjs-framework-field) - [Using the v7 store](#using-the-v7-store) - [v7-style story sort](#v7-style-story-sort) - [v7 Store API changes for addon authors](#v7-store-api-changes-for-addon-authors) - [Storyshots compatibility in the v7 store](#storyshots-compatibility-in-the-v7-store) - [Emotion11 quasi-compatibility](#emotion11-quasi-compatibility) - [Babel mode v7](#babel-mode-v7) - [Loader behavior with args changes](#loader-behavior-with-args-changes) - [6.4 Angular changes](#64-angular-changes) - [SB Angular builder](#sb-angular-builder) - [Angular13](#angular13) - [Angular component parameter removed](#angular-component-parameter-removed) - [6.4 deprecations](#64-deprecations) - [Deprecated --static-dir CLI flag](#deprecated---static-dir-cli-flag) - [From version 6.2.x to 6.3.0](#from-version-62x-to-630) - [Webpack 5](#webpack-5) - [Fixing hoisting issues](#fixing-hoisting-issues) - [Webpack 5 manager build](#webpack-5-manager-build) - [Wrong webpack version](#wrong-webpack-version) - [Angular 12 upgrade](#angular-12-upgrade) - [Lit support](#lit-support) - [No longer inferring default values of args](#no-longer-inferring-default-values-of-args) - [6.3 deprecations](#63-deprecations) - [Deprecated addon-knobs](#deprecated-addon-knobs) - [Deprecated scoped blocks imports](#deprecated-scoped-blocks-imports) - [Deprecated layout URL params](#deprecated-layout-url-params) - [From version 6.1.x to 6.2.0](#from-version-61x-to-620) - [MDX pattern tweaked](#mdx-pattern-tweaked) - [6.2 Angular overhaul](#62-angular-overhaul) - [New Angular storyshots format](#new-angular-storyshots-format) - [Deprecated Angular story component](#deprecated-angular-story-component) - [New Angular renderer](#new-angular-renderer) - [Components without selectors](#components-without-selectors) - [Packages now available as ESModules](#packages-now-available-as-esmodules) - [6.2 Deprecations](#62-deprecations) - [Deprecated implicit PostCSS loader](#deprecated-implicit-postcss-loader) - [Deprecated default PostCSS plugins](#deprecated-default-postcss-plugins) - [Deprecated showRoots config option](#deprecated-showroots-config-option) - [Deprecated control.options](#deprecated-controloptions) - [Deprecated storybook components html entry point](#deprecated-storybook-components-html-entry-point) - [From version 6.0.x to 6.1.0](#from-version-60x-to-610) - [Addon-backgrounds preset](#addon-backgrounds-preset) - [Single story hoisting](#single-story-hoisting) - [React peer dependencies](#react-peer-dependencies) - [6.1 deprecations](#61-deprecations) - [Deprecated DLL flags](#deprecated-dll-flags) - [Deprecated storyFn](#deprecated-storyfn) - [Deprecated onBeforeRender](#deprecated-onbeforerender) - [Deprecated grid parameter](#deprecated-grid-parameter) - [Deprecated package-composition disabled parameter](#deprecated-package-composition-disabled-parameter) - [From version 5.3.x to 6.0.x](#from-version-53x-to-60x) - [Hoisted CSF annotations](#hoisted-csf-annotations) - [Zero config typescript](#zero-config-typescript) - [Correct globs in main.js](#correct-globs-in-mainjs) - [CRA preset removed](#cra-preset-removed) - [Core-JS dependency errors](#core-js-dependency-errors) - [Args passed as first argument to story](#args-passed-as-first-argument-to-story) - [6.0 Docs breaking changes](#60-docs-breaking-changes) - [Remove framework-specific docs presets](#remove-framework-specific-docs-presets) - [Preview/Props renamed](#previewprops-renamed) - [Docs theme separated](#docs-theme-separated) - [DocsPage slots removed](#docspage-slots-removed) - [React prop tables with Typescript](#react-prop-tables-with-typescript) - [ConfigureJSX true by default in React](#configurejsx-true-by-default-in-react) - [User babelrc disabled by default in MDX](#user-babelrc-disabled-by-default-in-mdx) - [Docs description parameter](#docs-description-parameter) - [6.0 Inline stories](#60-inline-stories) - [New addon presets](#new-addon-presets) - [Removed babel-preset-vue from Vue preset](#removed-babel-preset-vue-from-vue-preset) - [Removed Deprecated APIs](#removed-deprecated-apis) - [New setStories event](#new-setstories-event) - [Removed renderCurrentStory event](#removed-rendercurrentstory-event) - [Removed hierarchy separators](#removed-hierarchy-separators) - [No longer pass denormalized parameters to storySort](#no-longer-pass-denormalized-parameters-to-storysort) - [Client API changes](#client-api-changes) - [Removed Legacy Story APIs](#removed-legacy-story-apis) - [Can no longer add decorators/parameters after stories](#can-no-longer-add-decoratorsparameters-after-stories) - [Changed Parameter Handling](#changed-parameter-handling) - [Simplified Render Context](#simplified-render-context) - [Story Store immutable outside of configuration](#story-store-immutable-outside-of-configuration) - [Improved story source handling](#improved-story-source-handling) - [6.0 Addon API changes](#60-addon-api-changes) - [Consistent local addon paths in main.js](#consistent-local-addon-paths-in-mainjs) - [Deprecated setAddon](#deprecated-setaddon) - [Deprecated disabled parameter](#deprecated-disabled-parameter) - [Actions addon uses parameters](#actions-addon-uses-parameters) - [Removed action decorator APIs](#removed-action-decorator-apis) - [Removed withA11y decorator](#removed-witha11y-decorator) - [Essentials addon disables differently](#essentials-addon-disables-differently) - [Backgrounds addon has a new api](#backgrounds-addon-has-a-new-api) - [6.0 Deprecations](#60-deprecations) - [Deprecated addon-info, addon-notes](#deprecated-addon-info-addon-notes) - [Deprecated addon-contexts](#deprecated-addon-contexts) - [Removed addon-centered](#removed-addon-centered) - [Deprecated polymer](#deprecated-polymer) - [Deprecated immutable options parameters](#deprecated-immutable-options-parameters) - [Deprecated addParameters and addDecorator](#deprecated-addparameters-and-adddecorator) - [Deprecated clearDecorators](#deprecated-cleardecorators) - [Deprecated configure](#deprecated-configure) - [Deprecated support for duplicate kinds](#deprecated-support-for-duplicate-kinds) - [From version 5.2.x to 5.3.x](#from-version-52x-to-53x) - [To main.js configuration](#to-mainjs-configuration) - [Using main.js](#using-mainjs) - [Using preview.js](#using-previewjs) - [Using manager.js](#using-managerjs) - [Create React App preset](#create-react-app-preset) - [Description doc block](#description-doc-block) - [React Native Async Storage](#react-native-async-storage) - [Deprecate displayName parameter](#deprecate-displayname-parameter) - [Unified docs preset](#unified-docs-preset) - [Simplified hierarchy separators](#simplified-hierarchy-separators) - [Addon StoryShots Puppeteer uses external puppeteer](#addon-storyshots-puppeteer-uses-external-puppeteer) - [From version 5.1.x to 5.2.x](#from-version-51x-to-52x) - [Source-loader](#source-loader) - [Default viewports](#default-viewports) - [Grid toolbar-feature](#grid-toolbar-feature) - [Docs mode docgen](#docs-mode-docgen) - [storySort option](#storysort-option) - [From version 5.1.x to 5.1.10](#from-version-51x-to-5110) - [babel.config.js support](#babelconfigjs-support) - [From version 5.0.x to 5.1.x](#from-version-50x-to-51x) - [React native server](#react-native-server) - [Angular 7](#angular-7) - [CoreJS 3](#corejs-3) - [From version 5.0.1 to 5.0.2](#from-version-501-to-502) - [Deprecate webpack extend mode](#deprecate-webpack-extend-mode) - [From version 4.1.x to 5.0.x](#from-version-41x-to-50x) - [sortStoriesByKind](#sortstoriesbykind) - [Webpack config simplification](#webpack-config-simplification) - [Theming overhaul](#theming-overhaul) - [Story hierarchy defaults](#story-hierarchy-defaults) - [Options addon deprecated](#options-addon-deprecated) - [Individual story decorators](#individual-story-decorators) - [Addon backgrounds uses parameters](#addon-backgrounds-uses-parameters) - [Addon cssresources name attribute renamed](#addon-cssresources-name-attribute-renamed) - [Addon viewport uses parameters](#addon-viewport-uses-parameters) - [Addon a11y uses parameters, decorator renamed](#addon-a11y-uses-parameters-decorator-renamed) - [Addon centered decorator deprecated](#addon-centered-decorator-deprecated) - [New keyboard shortcuts defaults](#new-keyboard-shortcuts-defaults) - [New URL structure](#new-url-structure) - [Rename of the `--secure` cli parameter to `--https`](#rename-of-the---secure-cli-parameter-to---https) - [Vue integration](#vue-integration) - [From version 4.0.x to 4.1.x](#from-version-40x-to-41x) - [Private addon config](#private-addon-config) - [React 15.x](#react-15x) - [From version 3.4.x to 4.0.x](#from-version-34x-to-40x) - [React 16.3+](#react-163) - [Generic addons](#generic-addons) - [Knobs select ordering](#knobs-select-ordering) - [Knobs URL parameters](#knobs-url-parameters) - [Keyboard shortcuts moved](#keyboard-shortcuts-moved) - [Removed addWithInfo](#removed-addwithinfo) - [Removed RN packager](#removed-rn-packager) - [Removed RN addons](#removed-rn-addons) - [Storyshots Changes](#storyshots-changes) - [Webpack 4](#webpack-4) - [Babel 7](#babel-7) - [Create-react-app](#create-react-app) - [Upgrade CRA1 to babel 7](#upgrade-cra1-to-babel-7) - [Migrate CRA1 while keeping babel 6](#migrate-cra1-while-keeping-babel-6) - [start-storybook opens browser](#start-storybook-opens-browser) - [CLI Rename](#cli-rename) - [Addon story parameters](#addon-story-parameters) - [From version 3.3.x to 3.4.x](#from-version-33x-to-34x) - [From version 3.2.x to 3.3.x](#from-version-32x-to-33x) - [`babel-core` is now a peer dependency #2494](#babel-core-is-now-a-peer-dependency-2494) - [Base webpack config now contains vital plugins #1775](#base-webpack-config-now-contains-vital-plugins-1775) - [Refactored Knobs](#refactored-knobs) - [From version 3.1.x to 3.2.x](#from-version-31x-to-32x) - [Moved TypeScript addons definitions](#moved-typescript-addons-definitions) - [Updated Addons API](#updated-addons-api) - [From version 3.0.x to 3.1.x](#from-version-30x-to-31x) - [Moved TypeScript definitions](#moved-typescript-definitions) - [Deprecated head.html](#deprecated-headhtml) - [From version 2.x.x to 3.x.x](#from-version-2xx-to-3xx) - [Webpack upgrade](#webpack-upgrade) - [Packages renaming](#packages-renaming) - [Deprecated embedded addons](#deprecated-embedded-addons) ## From version 6.5.x to 7.0.0 ### Alpha release notes Storybook 7.0 is in early alpha. During the alpha, we are making a large number of breaking changes. We may also break the breaking changes based on what we learn during the development cycle. When 7.0 goes to beta, we will start stabilizing and adding various auto-migrations to help users upgrade more easily. In the meantime, these migration notes are the best available documentation on things you should know upgrading to 7.0. ### 7.0 breaking changes #### removed auto injection of @storybook/addon-actions decorator The `withActions` decorator is no longer automatically added to stories. This is because it is really only used in the html renderer, for all other renderers it's redundant. If you are using the html renderer and use the `handles` parameter, you'll need to manually add the `withActions` decorator: ```diff import globalThis from 'global'; +import { withActions } from '@storybook/addon-actions/decorator'; export default { component: globalThis.Components.Button, args: { label: 'Click Me!', }, parameters: { chromatic: { disable: true }, }, }; export const Basic = { parameters: { handles: [{ click: 'clicked', contextmenu: 'right clicked' }], }, + decorators: [withActions], }; ``` #### 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) In 7.0, most of Storybook's addons now export a `manager.js` entry point, which is automatically registered in Storybook's manager when the addon is listed in `.storybook/main.js`'s `addons` field. If your `.manager.js` config references `register.js` of any of the following addons, you can remove it: `a11y`, `actions`, `backgrounds`, `controls`, `interactions`, `jest`, `links`, `measure`, `outline`, `toolbars`, `viewport`. #### Change of root html IDs The root ID unto which storybook renders stories is renamed from `root` to `#storybook-root` to avoid conflicts with user's code. #### No more default export from `@storybook/addons` The default export from `@storybook/addons` has been removed. Please use the named exports instead: ```js import { addons } from '@storybook/addons'; ``` The named export has been available since 6.0 or earlier, so your updated code will be backwards-compatible with older versions of Storybook. #### Modern browser support Starting in storybook 7.0, storybook will no longer support IE11, amongst other legacy browser versions. We now transpile our code with a target of `chrome >= 100` and node code is transpiled with a target of `node >= 14`. This means code-features such as (but not limited to) `async/await`, arrow-functions, `const`,`let`, etc will exists in the code at runtime, and thus the runtime environment must support it. Not just the runtime needs to support it, but some legacy loaders for webpack or other transpilation tools might need to be updated as well. For example certain versions of webpack 4 had parsers that could not parse the new syntax (e.g. optional chaining). Some addons or libraries might depended on this legacy browser support, and thus might break. You might get an error like: ``` regeneratorRuntime is not defined ``` To fix these errors, the addon will have to be re-released with a newer browser-target for transpilation. This often looks something like this (but it's dependent on the build system the addon uses): ```js // babel.config.js module.exports = { presets: [ [ '@babel/preset-env', { shippedProposals: true, useBuiltIns: 'usage', corejs: '3', modules: false, targets: { chrome: '100' }, }, ], ], }; ``` Here's an example PR to one of the storybook addons: https://github.com/storybookjs/addon-coverage/pull/3 doing just that. #### No more configuration for manager The storybook manager is no longer built with webpack. Now it's built with esbuild. Therefore, it's no longer possible to configure the manager. Esbuild comes preconfigured to handle importing CSS, and images. If you're currently loading files other than CSS or images into the manager, you'll need to make changes so the files get converted to JS before publishing your addon. This means the preset value `managerWebpack` is no longer respected, and should be removed from presets and `main.js` files. Addons that run in the manager can depend on `react` and `@storybook/*` packages directly. They do not need to be peerDependencies. But very importantly, the build system ensures there will only be 1 version of these packages at runtime. The version will come from the `@storybook/ui` package, and not from the addon. For this reason it's recommended to have these dependencies as `devDependencies` in your addon's `package.json`. The full list of packages that Storybook's manager bundler makes available for addons is here: https://github.com/storybookjs/storybook/blob/next/code/lib/ui/src/globals/types.ts Addons in the manager will no longer be bundled together anymore, which means that if 1 fails, it doesn't break the whole manager. Each addon is imported into the manager as an ESM module that's bundled separately. #### start-storybook / build-storybook binaries removed SB6.x framework packages shipped binaries called `start-storybook` and `build-storybook`. In SB7.0, we've removed these binaries and replaced them with new commands in Storybook's CLI: `storybook dev` and `storybook build`. These commands will look for the `framework` field in your `.storybook/main.js` config--[which is now required](#framework-field-mandatory)--and use that to determine how to start/build your storybook. The benefit of this change is that it is now possible to install multiple frameworks in a project without having to worry about hoisting issues. A typical storybook project includes two scripts in your projects `package.json`: ```json { "scripts": { "storybook": "start-storybook ", "build-storybook": "build-storybook " } } ``` To convert this project to 7.0: ```json { "scripts": { "storybook": "storybook dev ", "build-storybook": "storybook build " }, "devDependencies": { "storybook": "next" } } ``` The new CLI commands remove the following flags: | flag | migration | | -------- | --------------------------------------------------------------------------------------------- | | --modern | No migration needed. [All ESM code is modern in SB7](#modern-esm--ie11-support-discontinued). | #### storyStoreV7 enabled by default SB6.4 introduced [Story Store V7](#story-store-v7), an optimization which allows code splitting for faster build and load times. This was an experimental, opt-in change and you can read more about it in [the migration notes below](#story-store-v7). TLDR: you can't use the legacy `storiesOf` API or dynamic titles in CSF. Now in 7.0, Story Store V7 is the default. You can opt-out of it by setting the feature flag in `.storybook/main.js`: ```js module.exports = { features: { storyStoreV7: false, }, }; ``` During the 7.0 dev cycle we will be preparing recommendations and utilities to make it easier for `storiesOf` users to upgrade. #### Webpack4 support discontinued SB7.0 no longer supports Webpack4. Depending on your project specifics, it might be possible to run your Storybook using the webpack5 builder without error. If you are running into errors, you can upgrade your project to Webpack5 or you can try debugging those errors. To upgrade: - If you're configuring webpack directly, see the Webpack5 [release announcement](https://webpack.js.org/blog/2020-10-10-webpack-5-release/) and [migration guide](https://webpack.js.org/migrate/5). - If you're using Create React App, see the [migration notes](https://github.com/facebook/create-react-app/blob/main/CHANGELOG.md#migrating-from-40x-to-500) to upgrade from V4 (Webpack4) to 5 During the 7.0 dev cycle we will be updating this section with useful resources as we run across them. #### Modern ESM / IE11 support discontinued SB7.0 compiles to modern ESM, meaning that IE11 is no longer supported. Over the course of the 7.0 dev cycle we will create recommendations for users who still require IE support. #### Framework field mandatory In 6.4 we introduced a new `main.js` field called [`framework`](#mainjs-framework-field). Starting in 7.0, this field is mandatory. The value of the `framework` field has also changed. In 6.4, valid values included `@storybook/react`, `@storybook/vue`, etc. In 7.0, frameworks also specify the builder to be used. For example, The current list of frameworks include: - `@storybook/angular` - `@storybook/html-webpack5` - `@storybook/preact-webpack5` - `@storybook/react-webpack5` - `@storybook/react-vite` - `@storybook/server-webpack5` - `@storybook/svelte-webpack5` - `@storybook/svelte-vite` - `@storybook/vue-webpack5` - `@storybook/vue-vite` - `@storybook/vue3-webpack5` - `@storybook/vue3-vite` - `@storybook/web-components-webpack5` - `@storybook/web-components-vite` We will be expanding this list over the course of the 7.0 development cycle. More info on the rationale here: [Frameworks RFC](https://www.notion.so/chromatic-ui/Frameworks-RFC-89f8aafe3f0941ceb4c24683859ed65c). #### frameworkOptions renamed In 7.0, the `main.js` fields `reactOptions` and `angularOptions` have been renamed. They are now options on the `framework` field: ```js module.exports = { framework: { name: '@storybook/react-webpack5', options: { fastRefresh: true }, }, }; ``` #### Framework standalone build moved In 7.0 the location of the standalone node API has moved to `@storybook/core-server`. If you used the React standalone API, for example, you might have written: ```js const { buildStandalone } = require('@storybook/react/standalone'); const options = {}; buildStandalone(options).then(() => console.log('done')); ``` In 7.0, you would now use: ```js const build = require('@storybook/core-server/standalone'); const options = {}; build(options).then(() => console.log('done')); ``` #### Docs modern inline rendering by default Storybook docs has a new rendering mode called "modern inline rendering" which unifies the way stories are rendered in Docs mode and in the canvas (aka story mode). It is still being stabilized in 7.0 dev cycle. If you run into trouble with inline rendering in docs, you can opt out of modern inline rendering in your `.storybook/main.js`: ```js module.exports = { features: { modernInlineRender: false, }, }; ``` #### Babel mode v7 by default Storybook now uses your project babel configuration differently as [described below in Babel Mode v7](#babel-mode-v7). This is now the default. To opt-out: ```js module.exports = { features: { babelModeV7: false, }, }; ``` #### 7.0 feature flags removed Storybook uses temporary feature flags to opt-in to future breaking changes or opt-in to legacy behaviors. For example: ```js module.exports = { features: { emotionAlias: false, }, }; ``` In 7.0 we've removed the following feature flags: | flag | migration instructions | | ------------------- | ---------------------------------------------------- | | `emotionAlias` | This flag is no longer needed and should be deleted. | | `breakingChangesV7` | This flag is no longer needed and should be deleted. | #### CLI option `--use-npm` deprecated With increased support for more package managers (pnpm), we have introduced the `--package-manager` CLI option. Please use `--package-manager=npm` to force NPM to be used to install dependencies when running Storybook CLI commands. Other valid options are `pnpm`, `yarn1`, and `yarn2` (`yarn2` is for versions 2 and higher). #### Vite builder uses vite config automatically When using a [Vite-based framework](#framework-field-mandatory), Storybook will automatically use your `vite.config.(ctm)js` config file starting in 7.0. Some settings will be overridden by storybook so that it can function properly, and the merged settings can be modified using `viteFinal` in `.storybook/main.js` (see the [Storybook Vite configuration docs](https://storybook.js.org/docs/react/builders/vite#configuration)). If you were using `viteFinal` in 6.5 to simply merge in your project's standard vite config, you can now remove it. #### Vite cache moved to node_modules/.cache/.vite-storybook Previously, Storybook's Vite builder placed cache files in node_modules/.vite-storybook. However, it's more common for tools to place cached files into `node_modules/.cache`, and putting them there makes it quick and easy to clear the cache for multiple tools at once. We don't expect this change will cause any problems, but it's something that users of Storybook Vite projects should know about. It can be configured by setting `cacheDir` in `viteFinal` within `.storybook/main.js` [Storybook Vite configuration docs](https://storybook.js.org/docs/react/builders/vite#configuration)). #### Removed docs.getContainer and getPage parameters It is no longer possible to set `parameters.docs.getContainer()` and `getPage()`. Instead use `parameters.docs.container` or `parameters.docs.page` directly. #### Removed STORYBOOK_REACT_CLASSES global This was a legacy global variable from the early days of react docgen. If you were using this variable, you can instead use docgen information which is added directly to components using `.__docgenInfo`. #### Icons API changed For addon authors who use the `Icons` component, its API has been updated in Storybook 7. ```diff export interface IconsProps extends ComponentProps { - icon?: IconKey; - symbol?: IconKey; + icon: IconType; + useSymbol?: boolean; } ``` Full change here: https://github.com/storybookjs/storybook/pull/18809 #### 'config' preset entry replaced with 'previewAnnotations' The preset field `'config'` has been replaced with `'previewAnnotations'`. `'config'` is now deprecated and will be removed in Storybook 8.0. Additionally, the internal field `'previewEntries'` has been removed. If you need a preview entry, just use a `'previewAnnotations'` file and don't export anything. #### Dropped support for Angular 12 and below Official [Angular 12 LTS support ends Nov 2022](https://angular.io/guide/releases#actively-supported-versions). With that, Storybook also drops its support for Angular 12 and below. In order to use Storybook 7.0, you need to upgrade to at least Angular 13. #### Addon-backgrounds: Removed deprecated grid parameter Starting in 7.0 the `grid.cellSize` parameter should now be `backgrounds.grid.cellSize`. This was [deprecated in SB 6.1](#deprecated-grid-parameter). #### Addon-docs: Removed deprecated blocks.js entry Removed `@storybook/addon-docs/blocks` entry. Import directly from `@storybook/addon-docs` instead. This was [deprecated in SB 6.3](#deprecated-scoped-blocks-imports). #### Addon-a11y: Removed deprecated withA11y decorator We removed the deprecated `withA11y` decorator. This was [deprecated in 6.0](#removed-witha11y-decorator) ### Docs Changes The information hierarchy of docs in Storybook has changed in 7.0. The main difference is that each docs is listed in the sidebar as a separate entry, rather than attached to individual stories. These changes are encapsulated in the following: #### Standalone docs files In Storybook 6.x, to create a standalone docs MDX file, you'd have to create a `.stories.mdx` file, and describe its location with the `Meta` doc block: ```mdx import { Meta } from '@storybook/addon-docs'; ``` In 7.0, things are a little simpler -- you should call the file `.mdx` (drop the `.stories`). This will mean behind the scenes there is no story attached to this entry. You may also drop the `title` and use autotitle (and leave the `Meta` component out entirely). Additionally, you can attach a standalone docs entry to a component, using the new `of={}` syntax on the `Meta` component: ```mdx import { Meta } from '@storybook/blocks'; import * as ComponentStories from './some-component.stories'; ``` You can create as many docs entries as you like for a given component. Note that if you attach a docs entry to a component it will replace the automatically generated entry from `DocsPage` (See below). By default docs entries are listed first for the component. You can sort them using story sorting. #### Referencing stories in docs files To reference a story in a MDX file, you should reference it with `of`: ```mdx import { Meta, Story } from '@storybook/blocks'; import * as ComponentStories from './some-component.stories'; ``` You can also reference a story from a different component: ```mdx import { Meta, Story } from '@storybook/blocks'; import * as ComponentStories from './some-component.stories'; import * as SecondComponentStories from './second-component.stories'; ``` #### Docs Page In 7.0, rather than rendering each story in "docs view mode", Docs Page operates by adding additional sidebar entries for each component. By default it uses the same template as was used in 6.x, and the entries are entitled `Docs`. You can configure Docs Page in `main.js`: ```js module.exports = { docs: { docsPage: 'automatic', // see below for alternatives defaultName: 'Docs', // set to change the name of generated docs entries }, }; ``` If you are migrating from 6.x your `docs.docsPage` option will have been set to `'automatic'`, which has the effect of enabling docs page for _every_ CSF file. However, as of 7.0, the new default is `true`, which requires opting into DocsPage per-CSF file, with the `docsPage` **tag** on your component export: ```ts export default { component: MyComponent // Tags are a new feature coming in 7.1, that we are using to drive this behaviour. tags: ['docsPage'] } ``` You can also set `docsPage: false` to opt-out of docs page entirely. You can change the default template in the same way as in 6.x, using the `docs.page` parameter. #### Configuring the Docs Container As in 6.x, you can override the docs container to configure docs further. This the container that each docs entry is rendered inside: ```js // in preview.js export const parameters = { docs: { container: // your container } } ``` You likely want to use the `DocsContainer` component exported by `@storybook/blocks` and consider the following examples: **Overriding theme**: To override the theme, you can continue to use the `docs.theme` parameter. **Overriding MDX components** If you want to override the MDX components supplied to your docs page, use the `MDXProvider` from `@mdx-js/react`: ```js import { MDXProvider } from '@mdx-js/react'; import { DocsContainer } from '@storybook/blocks'; import * as DesignSystem from 'your-design-system'; export const MyDocsContainer = (props) => ( ); ``` **_NOTE_**: due to breaking changes in MDX2, such override will _only_ apply to elements you create via the MDX syntax, not pure HTML -- ie. `## content` not `

content

`. #### External Docs Storybook 7.0 can be used in the above way in externally created projects (i.e. custom docs sites). Your `.mdx` files defined as above should be portable to other contexts. You simply need to render them in an `ExternalDocs` component: ```js // In your project somewhere: import { ExternalDocs } from '@storybook/blocks'; // Import all the preview entries from addons that need to operate in your external docs, // at a minimum likely your project's and your renderer's. import * as reactAnnotations from '@storybook/react/preview'; import * as previewAnnotations from '../.storybook/preview'; export default function App({ Component, pageProps }) { return ( ); } ``` #### MDX2 upgrade Storybook 7 Docs uses MDXv2 instead of MDXv1. This means an improved syntax, support for inline JS expression, and improved performance among [other benefits](https://mdxjs.com/blog/v2/). If you use `.stories.mdx` files in your project, you may need to edit them since MDX2 contains [breaking changes](https://mdxjs.com/migrating/v2/#update-mdx-files). We will update this section with specific pointers based on user feedback during the prerelease period and probably add an codemod to help streamline the upgrade before final 7.0 release. As part of the upgrade we deleted the codemod `mdx-to-csf` and will be replacing it with a more sophisticated version prior to release. #### Dropped source loader / storiesOf static snippets In SB 6.x, Storybook Docs used a webpack loader called `source-loader` to help display static code snippets. This was configurable using the `options.sourceLoaderOptions` field. In SB 7.0, we've moved to a faster, simpler alternative called `csf-plugin` that **only supports CSF**. It is configurable using the `options.csfPluginOptions` field. If you're using `storiesOf` and want to restore the previous behavior, you can add `source-loader` by hand to your webpack config using the following snippet in `main.js`: ```js module.exports = { webpackFinal: (config) => { config.modules.rules.push({ test: /\.stories\.[tj]sx?$/, use: [ { loader: require.resolve('@storybook/source-loader'), options: {} /* your sourceLoaderOptions here */, }, ], enforce: 'pre', }); return config; }, }; ``` #### Dropped addon-docs manual configuration Storybook Docs 5.x shipped with instructions for how to manually configure webpack and storybook without the use of Storybook's "presets" feature. Over time, these docs went out of sync. Now in Storybook 7 we have removed support for manual configuration entirely. #### Autoplay in docs Running play functions in docs is generally tricky, as they can steal focus and cause the window to scroll. Consequently, we've disabled play functions in docs by default. If your story depends on a play function to render correctly, _and_ you are confident the function autoplaying won't mess up your docs, you can set `parameters.docs.autoplay = true` to have it auto play. ### 7.0 Deprecations #### `Story` type deprecated In 6.x you were able to do this: ```ts import type { Story } from '@storybook/react'; export const MyStory: Story = () =>
; ``` But this will produce a deprecation warning in 7.0 because `Story` has been deprecated. To fix the deprecation warning, use the `StoryFn` type: ```ts import type { StoryFn } from '@storybook/react'; export const MyStory: StoryFn = () =>
; ``` This change is part of our move to CSF3, which uses objects instead of functions to represent stories. You can read more about the CSF3 format here: https://storybook.js.org/blog/component-story-format-3-0/ #### `ComponentStory`, `ComponentStoryObj`, `ComponentStoryFn` and `ComponentMeta` types are deprecated The type of StoryObj and StoryFn have been changed in 7.0 so that both the "component" as "the props of the component" will be accepted as the generic parameter. ```ts import type { Story } from '@storybook/react'; import { Button, ButtonProps } from './Button'; // This works in 7.0, making the ComponentX types redundant. const meta: Meta = { component: Button }; export const CSF3Story: StoryObj = { args: { label: 'Label' } }; export const CSF2Story: StoryFn = (args) =>