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.
21 lines
703 B
TypeScript
21 lines
703 B
TypeScript
import RefreshRuntime from 'react-refresh/runtime'
|
|
import type { RefreshRuntimeGlobals } from './runtime'
|
|
|
|
declare const self: Window & RefreshRuntimeGlobals
|
|
|
|
if (typeof self !== 'undefined') {
|
|
var $RefreshInjected$ = '__reactRefreshInjected'
|
|
|
|
// Only inject the runtime if it hasn't been injected
|
|
if (!self[$RefreshInjected$]) {
|
|
RefreshRuntime.injectIntoGlobalHook(self)
|
|
|
|
// Empty implementation to avoid "ReferenceError: variable is not defined" in module which didn't pass builtin:react-refresh-loader
|
|
self.$RefreshSig$ = () => (type) => type
|
|
self.$RefreshReg$ = () => {}
|
|
|
|
// Mark the runtime as injected to prevent double-injection
|
|
self[$RefreshInjected$] = true
|
|
}
|
|
}
|