Skip to content

Commit 670b60a

Browse files
committed
Remove duplicated config and update react refresh client
1 parent aee5849 commit 670b60a

File tree

6 files changed

+44
-146
lines changed

6 files changed

+44
-146
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// This file is currently required because the error overlay has a bug preventing the its outright disabling.
9+
10+
'use strict';
11+
12+
function handleRuntimeError() {
13+
// Stubbed out due to a bug.
14+
}
15+
function clearRuntimeErrors() {
16+
// Stubbed out due to a bug.
17+
}
18+
19+
module.exports = {
20+
handleRuntimeError,
21+
clearRuntimeErrors,
22+
};

packages/react-dev-utils/webpackFastRefreshDevClient.js

-138
This file was deleted.

packages/react-dev-utils/webpackHotDevClient.js

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

245245
function handleApplyUpdates(err, updatedModules) {
246-
if (err || !updatedModules || hadRuntimeError) {
246+
const hasReactRefresh = process.env.REACT_REFRESH;
247+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
248+
// React refresh can handle hot-reloading over errors.
249+
if (!hasReactRefresh && wantsForcedReload) {
247250
window.location.reload();
248251
return;
249252
}

packages/react-scripts/config/env.js

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ function getClientEnvironment(publicUrl) {
9393
WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST,
9494
WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
9595
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
96+
// Whether or not react-refresh is enabled.
97+
// react-refresh is not 100% stable at this time,
98+
// which is why it's disabled by default.
99+
REACT_REFRESH: process.env.REACT_REFRESH || false,
96100
}
97101
);
98102
// Stringify all values so we can feed into webpack DefinePlugin

packages/react-scripts/config/webpack.config.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ const appPackageJson = require(paths.appPackageJson);
4343
// Source maps are resource heavy and can cause out of memory issue for large source files.
4444
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
4545

46-
// React refresh isn't 100% stable right now. We have a feature flag to enable it.
47-
const shouldUseReactRefresh = process.env.REACT_REFRESH === 'true';
48-
const webpackDevClientEntry = shouldUseReactRefresh
49-
? require.resolve('react-dev-utils/webpackFastRefreshDevClient')
50-
: require.resolve('react-dev-utils/webpackHotDevClient');
46+
const webpackDevClientEntry = require.resolve(
47+
'react-dev-utils/webpackHotDevClient'
48+
);
5149

5250
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
5351
// makes for a smoother build process.
@@ -85,6 +83,8 @@ module.exports = function(webpackEnv) {
8583
// Get environment variables to inject into our app.
8684
const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
8785

86+
const shouldUseReactRefresh = env.raw.REACT_REFRESH;
87+
8888
// common function to get style loaders
8989
const getStyleLoaders = (cssOptions, preProcessor) => {
9090
const loaders = [
@@ -168,7 +168,7 @@ module.exports = function(webpackEnv) {
168168
// the line below with these two lines if you prefer the stock client:
169169
// require.resolve('webpack-dev-server/client') + '?/',
170170
// require.resolve('webpack/hot/dev-server'),
171-
isEnvDevelopment && webpackDevClientEntry,
171+
isEnvDevelopment && !shouldUseReactRefresh && webpackDevClientEntry,
172172
// Finally, this is your app's code:
173173
paths.appIndexJs,
174174
// We include the app code last so that if there is a runtime error during
@@ -620,7 +620,13 @@ module.exports = function(webpackEnv) {
620620
// Provide fast-refresh https://github.com/facebook/react/tree/master/packages/react-refresh
621621
isEnvDevelopment &&
622622
shouldUseReactRefresh &&
623-
new ReactRefreshWebpackPlugin({ disableRefreshCheck: true }),
623+
new ReactRefreshWebpackPlugin({
624+
disableRefreshCheck: true,
625+
overlay: {
626+
entry: webpackDevClientEntry,
627+
module: require.resolve('react-dev-utils/errorOverlayModuleEntry'),
628+
},
629+
}),
624630
// Watcher doesn't work well if you mistype casing in a path so we use
625631
// a plugin that prints an error when you attempt to do this.
626632
// See https://github.com/facebook/create-react-app/issues/240

packages/react-scripts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"url-loader": "2.3.0",
8181
"webpack": "4.42.0",
8282
"webpack-dev-server": "3.10.3",
83+
"webpack-hot-middleware": "^2.25.0",
8384
"webpack-manifest-plugin": "2.2.0",
8485
"workbox-webpack-plugin": "4.3.1"
8586
},

0 commit comments

Comments
 (0)