Skip to content

Commit f109c0a

Browse files
javachemeta-codesync[bot]
authored andcommitted
Skip HMR client setup when bundle is not from Metro (#58428)
Summary: Pull Request resolved: #58428 When the JS bundle is loaded from a local file (bundled with the app or restored from disk), `HMRClient.setup()` still runs during startup and registers an entry-point with the packager over the fallback `/hot?bundleEntry=...` URL. There is no coherent module map to hot-reload against, so the packager side logs an "Unable to resolve module" error. Gate `setup()` on `getDevServer().bundleLoadedFromServer` and early-return with a `console.warn` when the bundle did not come from Metro. The user still sees why HMR is unavailable in this session, but the noisy resolver error goes away. Changelog: [General][Fixed] - Skip HMR client setup when the JS bundle was not loaded from Metro Reviewed By: vzaidman Differential Revision: D110603320 fbshipit-source-id: 63a3c19d886598bc934c9bbdd90b32a8eb8d5aad
1 parent 506165d commit f109c0a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎packages/react-native/Libraries/Utilities/HMRClient.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ const HMRClient: HMRClientNativeInterface = {
162162
invariant(host, 'Missing required parameter `host`');
163163
invariant(!hmrClient, 'Cannot initialize hmrClient twice');
164164

165+
// HMR requires a Metro-served bundle so the server can map source edits back
166+
// to the running module set. When the bundle was loaded from a local file
167+
// there's nothing to hot-reload — registering with the server would just log
168+
// spurious "Unable to resolve module" errors.
169+
if (!getDevServer().bundleLoadedFromServer) {
170+
console.warn(
171+
'Not enabling Hot Module Reloading: the JS bundle was loaded from a local ' +
172+
'file, not from Metro. To use HMR, load the bundle from the packager.',
173+
);
174+
return;
175+
}
176+
165177
// Moving to top gives errors due to NativeModules not being initialized
166178
const DevLoadingView = require('./DevLoadingView').default;
167179

0 commit comments

Comments
 (0)