-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12470 from storybookjs/react/refresh2
React: Add react-refresh
- Loading branch information
Showing
18 changed files
with
209 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import webpack from 'webpack'; | ||
import * as preset from './framework-preset-react'; | ||
import type { StorybookOptions } from './types'; | ||
|
||
describe('framework-preset-react', () => { | ||
const babelLoaderPath = require.resolve('babel-loader'); | ||
const reactRefreshPath = require.resolve('react-refresh/babel'); | ||
const webpackConfigMock: webpack.Configuration = { | ||
mode: 'development', | ||
plugins: [], | ||
module: { | ||
rules: [], | ||
}, | ||
}; | ||
|
||
describe('webpackFinal', () => { | ||
it('should return a config with fast refresh plugin when fast refresh is enabled', () => { | ||
const config = preset.webpackFinal(webpackConfigMock, { | ||
reactOptions: { fastRefresh: true }, | ||
} as StorybookOptions); | ||
|
||
expect(config.module.rules).toEqual([ | ||
{ | ||
test: /\.[jt]sx?$/, | ||
exclude: /node_modules/, | ||
use: [ | ||
{ | ||
loader: babelLoaderPath, | ||
options: { | ||
plugins: [reactRefreshPath], | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should not return a config with fast refresh plugin when fast refresh is disabled', () => { | ||
const config = preset.webpackFinal(webpackConfigMock, { | ||
reactOptions: { fastRefresh: false }, | ||
} as StorybookOptions); | ||
|
||
expect(config.module.rules).toEqual([]); | ||
}); | ||
|
||
it('should not return a config with fast refresh plugin when mode is not development', () => { | ||
const config = preset.webpackFinal({ ...webpackConfigMock, mode: 'production' }, { | ||
reactOptions: { fastRefresh: true }, | ||
} as StorybookOptions); | ||
|
||
expect(config.module.rules).toEqual([]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { StorybookOptions as BaseOptions } from '@storybook/core/types'; | ||
|
||
/** | ||
* The internal options object, used by Storybook frameworks and addons. | ||
*/ | ||
export interface StorybookOptions extends BaseOptions { | ||
reactOptions?: { | ||
fastRefresh?: boolean; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { StorybookConfig as BaseConfig } from '@storybook/core/types'; | ||
|
||
/** | ||
* The interface for Storybook configuration in `main.ts` files. | ||
*/ | ||
export interface StorybookConfig extends BaseConfig { | ||
reactOptions?: { | ||
fastRefresh?: boolean; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
examples/official-storybook/stories/addon-docs/react-refresh-example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
export const Refresh = () => { | ||
const [value, setValue] = React.useState('abc'); | ||
return ( | ||
<> | ||
<input value={value} onChange={(event) => setValue(event.target.value)} /> | ||
<p>Change the input value then this text in the component.</p> | ||
<p>The state of the input should be kept.</p> | ||
</> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
examples/official-storybook/stories/addon-docs/react-refresh.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { Refresh } from './react-refresh-example'; | ||
|
||
export default { | ||
title: 'Core/React Refresh', | ||
}; | ||
|
||
export const Default = () => <Refresh />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4738,6 +4738,18 @@ | |
"@parcel/utils" "^1.11.0" | ||
physical-cpu-count "^2.0.0" | ||
|
||
"@pmmmwh/react-refresh-webpack-plugin@^0.4.2": | ||
version "0.4.2" | ||
resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.4.2.tgz#1f9741e0bde9790a0e13272082ed7272a083620d" | ||
integrity sha512-Loc4UDGutcZ+Bd56hBInkm6JyjyCwWy4t2wcDXzN8EDPANgVRj0VP8Nxn0Zq2pc+WKauZwEivQgbDGg4xZO20A== | ||
dependencies: | ||
ansi-html "^0.0.7" | ||
error-stack-parser "^2.0.6" | ||
html-entities "^1.2.1" | ||
native-url "^0.2.6" | ||
schema-utils "^2.6.5" | ||
source-map "^0.7.3" | ||
|
||
"@popperjs/core@^2.4.4": | ||
version "2.4.4" | ||
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.4.4.tgz#11d5db19bd178936ec89cd84519c4de439574398" | ||
|
@@ -14202,7 +14214,7 @@ error-ex@^1.2.0, error-ex@^1.3.1: | |
dependencies: | ||
is-arrayish "^0.2.1" | ||
|
||
error-stack-parser@^2.0.0, error-stack-parser@^2.0.1: | ||
error-stack-parser@^2.0.0, error-stack-parser@^2.0.1, error-stack-parser@^2.0.6: | ||
version "2.0.6" | ||
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.6.tgz#5a99a707bd7a4c58a797902d48d82803ede6aad8" | ||
integrity sha512-d51brTeqC+BHlwF0BhPtcYgF5nlzf9ZZ0ZIUQNZpc9ZB9qw5IJ2diTrBY9jlCJkTLITYPjmiX6OWCwH+fuyNgQ== | ||
|
@@ -23593,6 +23605,13 @@ napi-macros@~2.0.0: | |
resolved "https://registry.yarnpkg.com/napi-macros/-/napi-macros-2.0.0.tgz#2b6bae421e7b96eb687aa6c77a7858640670001b" | ||
integrity sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg== | ||
|
||
native-url@^0.2.6: | ||
version "0.2.6" | ||
resolved "https://registry.yarnpkg.com/native-url/-/native-url-0.2.6.tgz#ca1258f5ace169c716ff44eccbddb674e10399ae" | ||
integrity sha512-k4bDC87WtgrdD362gZz6zoiXQrl40kYlBmpfmSjwRO1VU0V5ccwJTlxuE72F6m3V0vc1xOf6n3UCP9QyerRqmA== | ||
dependencies: | ||
querystring "^0.2.0" | ||
|
||
natural-compare@^1.4.0: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" | ||
|
@@ -27579,6 +27598,11 @@ react-popper@^2.2.3: | |
react-fast-compare "^3.0.1" | ||
warning "^4.0.2" | ||
|
||
react-refresh@^0.8.3: | ||
version "0.8.3" | ||
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" | ||
integrity sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg== | ||
|
||
[email protected]: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-3.0.1.tgz#e5565350d8069cc9966b5998d3fe3befe3d243ac" | ||
|