Skip to content

Commit

Permalink
fix: avoid double react refresh transform in rspack-dev-server (#4243)
Browse files Browse the repository at this point in the history
fix: double react refresh transform
  • Loading branch information
ahabhgk authored Sep 25, 2023
1 parent a757197 commit 95d63b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,21 @@ export class RspackDevServer extends WebpackDevServer {
// enable react.refresh by default
compiler.options.builtins.react.refresh ??= true;
if (compiler.options.builtins.react.refresh) {
new ReactRefreshPlugin().apply(compiler);
const runtimePaths = ReactRefreshPlugin.deprecated_runtimePaths;
new compiler.webpack.EntryPlugin(
compiler.context,
runtimePaths[0],
{
name: undefined
}
).apply(compiler);
new compiler.webpack.ProvidePlugin({
$ReactRefreshRuntime$: runtimePaths[1]
}).apply(compiler);
compiler.options.module.rules.unshift({
include: runtimePaths,
type: "js"
});
}
}
} else if (compiler.options.builtins.react.refresh) {
Expand Down
4 changes: 3 additions & 1 deletion packages/rspack-plugin-react-refresh/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const refreshRuntimeDirPath = path.dirname(
})
);
const runtimePaths = [
reactRefreshEntryPath,
reactRefreshPath,
refreshUtilsPath,
reactRefreshEntryPath,
refreshRuntimeDirPath
];

Expand Down Expand Up @@ -61,3 +61,5 @@ module.exports = class ReactRefreshRspackPlugin {
});
}
};

module.exports.deprecated_runtimePaths = runtimePaths;

0 comments on commit 95d63b4

Please sign in to comment.