Skip to content

Commit 15fef8e

Browse files
jbromafacebook-github-bot
authored andcommitted
refactor: prevent reinitializing global.$RefreshReg$ (#1510)
Summary: Part of #1480 This PR adds a check for global.$RefreshReg$ to prevent reinitialising it in case there are multiple module systems present in runtime (like it does in the implementation of module-federation in Metro). For context: for the HMR in MF we're reusing the global instance of `ReactRefresh` <!-- Changelog entries should be prefixed with one of the following scopes: [Breaking, Feature, Fix, Performance, Deprecated, Experimental, Internal] Examples: Changelog: [Fix] Respond with HTTP 404 when a bundle entry point cannot be resolved Changelog: [Internal] --> Changelog: [Internal] Prevent reinitialising global.$RefreshReg$ in require.js polyfill Pull Request resolved: #1510 Test Plan: n/a Reviewed By: huntie Differential Revision: D75678288 Pulled By: robhogan fbshipit-source-id: 2f7eb8ac3b298494b260276b1ab74e35230e3743
1 parent 0686024 commit 15fef8e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/metro-runtime/src/polyfills/require.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ const CYCLE_DETECTED = {};
9494
const {hasOwnProperty} = {};
9595

9696
if (__DEV__) {
97-
global.$RefreshReg$ = () => {};
98-
global.$RefreshSig$ = () => type => type;
97+
global.$RefreshReg$ = global.$RefreshReg$ ?? (() => {});
98+
global.$RefreshSig$ = global.$RefreshSig$ ?? (() => type => type);
9999
}
100100

101101
function clear(): ModuleList {

0 commit comments

Comments
 (0)