diff --git a/packages/react-native/Libraries/Utilities/HMRClient.js b/packages/react-native/Libraries/Utilities/HMRClient.js index c15cb4eff75..1f67f3e9b9d 100644 --- a/packages/react-native/Libraries/Utilities/HMRClient.js +++ b/packages/react-native/Libraries/Utilities/HMRClient.js @@ -23,6 +23,7 @@ const prettyFormat = require('pretty-format'); const pendingEntryPoints = []; let hmrClient = null; let hmrUnavailableReason: string | null = null; +let hmrOrigin: string | null = null; let currentCompileErrorMessage: string | null = null; let didConnect: boolean = false; let pendingLogs: Array<[LogLevel, $ReadOnlyArray]> = []; @@ -100,7 +101,14 @@ const HMRClient: HMRClientNativeInterface = { }, registerBundle(requestUrl: string) { - invariant(hmrClient, 'Expected HMRClient.setup() call at startup.'); + invariant( + hmrOrigin != null && hmrClient != null, + 'Expected HMRClient.setup() call at startup.', + ); + // only process registerBundle calls from the same origin + if (!requestUrl.startsWith(hmrOrigin)) { + return; + } pendingEntryPoints.push(requestUrl); registerBundleEntryPoints(hmrClient); }, @@ -162,8 +170,10 @@ const HMRClient: HMRClientNativeInterface = { const serverScheme = scheme; - const client = new MetroHMRClient(`${serverScheme}://${serverHost}/hot`); + const origin = `${serverScheme}://${serverHost}`; + const client = new MetroHMRClient(`${origin}/hot`); + hmrOrigin = origin; hmrClient = client; const {fullBundleUrl} = getDevServer();