Skip to content

Commit 3457489

Browse files
authored
chore(docs): Add auto config change for react-dom in Storybook (#37222)
1 parent cb92dfe commit 3457489

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/docs/how-to/testing/visual-testing-with-storybook.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,18 @@ Storybook's webpack configuration will require adjustments to allow you to trans
6464
In your Storybook configuration file (i.e., `.storybook/main.js`) add the following:
6565

6666
```js:title=.storybook/main.js
67+
const React = require("react");
68+
6769
module.exports = {
6870
webpackFinal: async config => {
6971
// Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
7072
config.module.rules[0].exclude = [/node_modules\/(?!(gatsby|gatsby-script)\/)/]
7173

74+
// Use correct react-dom depending on React version.
75+
if (parseInt(React.version) <= 18) {
76+
config.externals = ["react-dom/client"];
77+
}
78+
7279
// Remove core-js to prevent issues with Storybook
7380
config.module.rules[0].exclude= [/core-js/]
7481
// Use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook
@@ -85,6 +92,8 @@ module.exports = {
8592
The final `.storybook/main.js` should look something like this:
8693

8794
```js:title=.storybook/main.js
95+
const React = require("react");
96+
8897
module.exports = {
8998
// You will want to change this to wherever your Stories will live
9099
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
@@ -98,6 +107,11 @@ module.exports = {
98107
// Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
99108
config.module.rules[0].exclude = [/node_modules\/(?!(gatsby|gatsby-script)\/)/]
100109

110+
// Use correct react-dom depending on React version.
111+
if (parseInt(React.version) <= 18) {
112+
config.externals = ["react-dom/client"];
113+
}
114+
101115
// Remove core-js to prevent issues with Storybook
102116
config.module.rules[0].exclude= [/core-js/]
103117
// Use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook

0 commit comments

Comments
 (0)