mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
5712c05c55
This commit addresses the bugs where Hot Module Replacement (HMR) was not functioning correctly in Rspack mode. Component edits would often result in no update or a full page reload instead of a fast, state-preserving refresh. This commit implements a new, custom React Refresh plugin and runtime specifically for Rspack, which correctly orchestrates the HMR lifecycle.
25 lines
686 B
TypeScript
25 lines
686 B
TypeScript
import type { Compiler } from 'webpack'
|
|
|
|
const PLUGIN_NAME = 'ReactRefreshRspackPlugin'
|
|
|
|
class ReactRefreshRspackPlugin {
|
|
static loader = 'builtin:react-refresh-loader'
|
|
|
|
apply(compiler: Compiler) {
|
|
new compiler.webpack.ProvidePlugin({
|
|
$ReactRefreshRuntime$: require.resolve('./internal/RspackReactRefresh'),
|
|
}).apply(compiler)
|
|
|
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
|
PLUGIN_NAME,
|
|
(_, runtimeRequirements) => {
|
|
runtimeRequirements.add(compiler.webpack.RuntimeGlobals.moduleCache)
|
|
}
|
|
)
|
|
})
|
|
}
|
|
}
|
|
|
|
export default ReactRefreshRspackPlugin
|