Skip to content

Commit 3c3ccba

Browse files
committed
migration notes.
1 parent 7d7777a commit 3c3ccba

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

MIGRATION.md

+49-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
- [7.0 feature flags removed](#70-feature-flags-removed)
2222
- [CLI option `--use-npm` deprecated](#cli-option---use-npm-deprecated)
2323
- [Vite builder uses vite config automatically](#vite-builder-uses-vite-config-automatically)
24-
- [Vite cache moved to node_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook)
24+
- [Vite cache moved to node\_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook)
2525
- [Removed docs.getContainer and getPage parameters](#removed-docsgetcontainer-and-getpage-parameters)
26-
- [Removed STORYBOOK_REACT_CLASSES global](#removed-storybook_react_classes-global)
26+
- [Removed STORYBOOK\_REACT\_CLASSES global](#removed-storybook_react_classes-global)
2727
- [Icons API changed](#icons-api-changed)
2828
- ['config' preset entry replaced with 'previewAnnotations'](#config-preset-entry-replaced-with-previewannotations)
2929
- [Dropped support for Angular 12 and below](#dropped-support-for-angular-12-and-below)
@@ -37,6 +37,8 @@
3737
- [Configuring the Docs Container](#configuring-the-docs-container)
3838
- [External Docs](#external-docs)
3939
- [MDX2 upgrade](#mdx2-upgrade)
40+
- [Default docs styles will leak into non-story user components](#default-docs-styles-will-leak-into-non-story-user-components)
41+
- [Explicit `<code>` elements are no longer syntax highlighted](#explicit-code-elements-are-no-longer-syntax-highlighted)
4042
- [Dropped source loader / storiesOf static snippets](#dropped-source-loader--storiesof-static-snippets)
4143
- [Dropped addon-docs manual configuration](#dropped-addon-docs-manual-configuration)
4244
- [Autoplay in docs](#autoplay-in-docs)
@@ -756,6 +758,47 @@ We will update this section with specific pointers based on user feedback during
756758

757759
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.
758760

761+
#### Default docs styles will leak into non-story user components
762+
763+
Storybook's default styles in docs are now globally applied to any element instead of using classes. This means that any component that you add directly in a docs file will also get the default styles.
764+
765+
To mitigate this you need to wrap any content you don't want styled with the `Unstyled` block like this:
766+
767+
```mdx
768+
import { Unstyled } from '@storybook/blocks';
769+
import { MyComponent } from './MyComponent';
770+
771+
# This is a header
772+
773+
<Unstyled>
774+
<MyComponent />
775+
</Unstyled>
776+
```
777+
778+
Components that are part of your stories or in a canvas will not need this mitigation, as the `Story` and `Canvas` blocks already have this built-in.
779+
780+
#### Explicit `<code>` elements are no longer syntax highlighted
781+
782+
Due to how MDX2 works differently from MDX1, manually defined `<code>` elements are no longer transformed to the `Code` component, so it will not be syntax highlighted. This is not the case for markdown \`\`\` code-fences, that will still end up as `Code` with syntax highlighting.
783+
784+
Luckily [MDX2 supports markdown (like code-fences) inside elements better now](https://mdxjs.com/blog/v2/#improvements-to-the-mdx-format), so most cases where you needed a `<code>` element before, you can use code-fences instead:
785+
786+
<!-- prettier-ignore-start -->
787+
````md
788+
<code>This will now be an unstyled line of code</code>
789+
790+
```js
791+
const a = 'This is still a styled code block.';
792+
```
793+
794+
<div style={{ background: 'red', padding: '10px' }}>
795+
```js
796+
const a = 'MDX2 supports markdown in elements better now, so this is possible.';
797+
```
798+
</div>
799+
````
800+
<!-- prettier-ignore-end -->
801+
759802
#### Dropped source loader / storiesOf static snippets
760803

761804
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.
@@ -3621,3 +3664,7 @@ If you **are** using these addons, it takes two steps to migrate:
36213664
```
36223665
36233666
<!-- markdown-link-check-enable -->
3667+
3668+
```
3669+
3670+
```

code/ui/blocks/src/components/DocsPage.stories.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Preview from './Preview.stories';
99
import * as argsTable from './ArgsTable/ArgsTable.stories';
1010
import * as source from './Source.stories';
1111
import * as description from './Description.stories';
12+
import { Unstyled } from '../blocks/Unstyled';
1213

1314
export default {
1415
component: DocsPageWrapper,
@@ -109,14 +110,16 @@ export const Html = {
109110
<div>Div</div>
110111
<a>Nested A tag</a>
111112
</div>
112-
<div className="sb-unstyled" style={{ border: '2px solid red' }}>
113-
<h1>Unstyled content</h1>
114-
<h2>Heading 2</h2>
115-
<a>A tag</a>
116-
<div>
117-
<div>Div</div>
118-
<a>Nested A tag</a>
119-
</div>
113+
<div style={{ border: '2px solid red' }}>
114+
<Unstyled>
115+
<h1>Unstyled content</h1>
116+
<h2>Heading 2</h2>
117+
<a>A tag</a>
118+
<div>
119+
<div>Div</div>
120+
<a>Nested A tag</a>
121+
</div>
122+
</Unstyled>
120123
</div>
121124
</DocsPageWrapper>
122125
),

prettier.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./scripts/prettier.config');

0 commit comments

Comments
 (0)