Skip to content

Commit 832ebd5

Browse files
iansuabhiisheek
authored andcommitted
Add Fast Refresh warning when using React < 16.10 (facebook#9350)
1 parent 75cda04 commit 832ebd5

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

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

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) {

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

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

@@ -105,6 +109,7 @@ checkBrowsers(paths.appPath, isInteractive)
105109
// ---- Custom Config Support End ----
106110
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
107111
const appName = require(paths.appPackageJson).name;
112+
108113
const useTypeScript = fs.existsSync(paths.appTsConfig);
109114
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
110115
const urls = prepareUrls(
@@ -162,6 +167,14 @@ checkBrowsers(paths.appPath, isInteractive)
162167
clearConsole();
163168
}
164169

170+
if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
171+
console.log(
172+
chalk.yellow(
173+
`Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
174+
)
175+
);
176+
}
177+
165178
console.log(chalk.cyan('Starting the development server...\n'));
166179
openBrowser(urls.localUrlForBrowser);
167180
});

0 commit comments

Comments
 (0)