Skip to content

Commit aeaf575

Browse files
authoredAug 2, 2020
Add Fast Refresh warning when using React < 16.10 (#9350)
1 parent 1a6ef92 commit aeaf575

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed
 

Diff for: ‎docusaurus/docs/advanced-configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ You can adjust various development and production settings by setting environmen
2525
| INLINE_RUNTIME_CHUNK | 🚫 Ignored | ✅ Used | By default, Create React App will embed the runtime script into `index.html` during the production build. When set to `false`, the script will not be embedded and will be imported as usual. This is normally required when dealing with CSP. |
2626
| IMAGE_INLINE_SIZE_LIMIT | 🚫 Ignored | ✅ Used | By default, images smaller than 10,000 bytes are encoded as a data URI in base64 and inlined in the CSS or JS build artifact. Set this to control the size limit in bytes. Setting it to 0 will disable the inlining of images. |
2727
| EXTEND_ESLINT | ✅ Used | ✅ Used | When set to `true`, user provided ESLint configs will be used by `eslint-loader`. Note that any rules set to `"error"` will stop the application from building. |
28-
| FAST_REFRESH | ✅ Used | 🚫 Ignored | When set to `true`, enables experimental support for fast refresh to allow you to tweak your components in real time without reloading the page. |
28+
| FAST_REFRESH | ✅ Used | 🚫 Ignored | When set to `false`, disables experimental support for Fast Refresh to allow you to tweak your components in real time without reloading the page. |
2929
| TSC_COMPILE_ON_ERROR | ✅ Used | ✅ Used | When set to `true`, you can run and properly build TypeScript projects even if there are TypeScript type check errors. These errors are printed as warnings in the terminal and/or browser console. |

Diff for: ‎packages/react-dev-utils/webpackHotDevClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function tryApplyUpdates(onHotUpdateSuccess) {
243243
}
244244

245245
function handleApplyUpdates(err, updatedModules) {
246-
const hasReactRefresh = process.env.FAST_REFRESH;
246+
const hasReactRefresh = process.env.FAST_REFRESH !== 'false';
247247
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
248248
// React refresh can handle hot-reloading over errors.
249249
if (!hasReactRefresh && wantsForcedReload) {

Diff for: ‎packages/react-scripts/config/env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function getClientEnvironment(publicUrl) {
9797
// react-refresh is not 100% stable at this time,
9898
// which is why it's disabled by default.
9999
// It is defined here so it is available in the webpackHotDevClient.
100-
FAST_REFRESH: process.env.FAST_REFRESH || false,
100+
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
101101
}
102102
);
103103
// Stringify all values so we can feed into webpack DefinePlugin

Diff for: ‎packages/react-scripts/scripts/start.js

+13
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ const {
4444
prepareUrls,
4545
} = require('react-dev-utils/WebpackDevServerUtils');
4646
const openBrowser = require('react-dev-utils/openBrowser');
47+
const semver = require('semver');
4748
const paths = require('../config/paths');
4849
const configFactory = require('../config/webpack.config');
4950
const createDevServerConfig = require('../config/webpackDevServer.config');
51+
const getClientEnvironment = require('../config/env');
52+
const react = require(require.resolve('react', { paths: [paths.appPath] }));
5053

54+
const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
5155
const useYarn = fs.existsSync(paths.yarnLockFile);
5256
const isInteractive = process.stdout.isTTY;
5357

@@ -95,6 +99,7 @@ checkBrowsers(paths.appPath, isInteractive)
9599
const config = configFactory('development');
96100
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
97101
const appName = require(paths.appPackageJson).name;
102+
98103
const useTypeScript = fs.existsSync(paths.appTsConfig);
99104
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
100105
const urls = prepareUrls(
@@ -142,6 +147,14 @@ checkBrowsers(paths.appPath, isInteractive)
142147
clearConsole();
143148
}
144149

150+
if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
151+
console.log(
152+
chalk.yellow(
153+
`Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
154+
)
155+
);
156+
}
157+
145158
console.log(chalk.cyan('Starting the development server...\n'));
146159
openBrowser(urls.localUrlForBrowser);
147160
});

0 commit comments

Comments
 (0)