Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/metro-runtime/src/polyfills/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ function loadModuleImplementation(
if (Refresh != null) {
const RefreshRuntime = Refresh;
global.$RefreshReg$ = (type, id) => {
RefreshRuntime.register(type, moduleId + ' ' + id);
// prefix the id with global prefix to enable multiple HMR clients
const prefixedModuleId =
__METRO_GLOBAL_PREFIX__ + ' ' + moduleId + ' ' + id;
RefreshRuntime.register(type, prefixedModuleId);
};
global.$RefreshSig$ =
RefreshRuntime.createSignatureFunctionForTransform;
Expand Down Expand Up @@ -492,7 +495,13 @@ function loadModuleImplementation(
Systrace.endEvent();

if (Refresh != null) {
registerExportsForReactRefresh(Refresh, moduleObject.exports, moduleId);
// prefix the id with global prefix to enable multiple HMR clients
const prefixedModuleId = __METRO_GLOBAL_PREFIX__ + ' ' + moduleId;
registerExportsForReactRefresh(
Refresh,
moduleObject.exports,
prefixedModuleId,
);
}
}

Expand Down Expand Up @@ -986,7 +995,7 @@ if (__DEV__) {
var registerExportsForReactRefresh = (
Refresh: any,
moduleExports: Exports,
moduleID: ModuleID,
moduleID: string,
) => {
Refresh.register(moduleExports, moduleID + ' %exports%');
if (moduleExports == null || typeof moduleExports !== 'object') {
Expand Down Expand Up @@ -1025,8 +1034,10 @@ if (__DEV__) {

var requireRefresh = function requireRefresh() {
return (
global[__METRO_GLOBAL_PREFIX__ + '__ReactRefresh'] ||
global[global.__METRO_GLOBAL_PREFIX__ + '__ReactRefresh'] ||
// $FlowFixMe[prop-missing]
global[__METRO_GLOBAL_PREFIX__ + '__ReactRefresh'] || metroRequire.Refresh
metroRequire.Refresh
);
};
}
Loading