Skip to content

Commit a7b7ed7

Browse files
committed
Handle race condition with Webpack compilation
Workaround for this issue: webpack/webpack#19837
1 parent e17bdb0 commit a7b7ed7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ function webpack5(this: ReactFreshWebpackPlugin, compiler: WebpackCompiler) {
105105
`options.factory = ${runtimeTemplate.basicFunction(
106106
'moduleObject, moduleExports, webpackRequire',
107107
[
108+
// If the original factory is missing, e.g. due to race condition
109+
// when compiling multiple entries concurrently, recover by doing
110+
// a full page reload.
111+
'if (!originalFactory) {',
112+
Template.indent('document.location.reload();'),
113+
Template.indent('return;'),
114+
'}',
108115
// Legacy CSS implementations will `eval` browser code in a Node.js
109116
// context to extract CSS. For backwards compatibility, we need to check
110117
// we're in a browser context before continuing.

0 commit comments

Comments
 (0)