Files
react-native/Libraries/Core/setUpBatchedBridge.js
T
Dan Abramov abc663dd5a Add a shim for HMRClient in prod bundles
Summary:
Running a PROD JS bundle with a DEV binary used to redbox with Fast Refresh on. The error said "HMRClient is not a registered callable module".

This isn't a new issue: https://www.google.com/search?q=%22hmrclient%20is%20not%20a%20registered%22. However, now it happens every time because `setup()` is now called unconditionally in a DEV native build.

Because a combination of DEV binary + PROD JS is technically possible, I'm adding a tiny shim that will make it a no-op instead of crashing. It will also explain what's wrong if you *intentionally* try to turn on Fast Refresh.

Reviewed By: sahrens

Differential Revision: D16145378

fbshipit-source-id: 0b9c0a6f30c02ca7f4a0133048450bdde3576ad2
2019-07-07 13:25:10 -07:00

63 lines
2.0 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
/**
* We don't set up the batched bridge in bridgeless mode. Once we've migrated
* everything over to bridgeless we can just delete this file.
*/
if (!global.RN$Bridgeless) {
/**
* Set up the BatchedBridge. This must be done after the other steps in
* InitializeCore to ensure that the JS environment has been initialized.
* You can use this module directly, or just require InitializeCore.
*/
const BatchedBridge = require('../BatchedBridge/BatchedBridge');
BatchedBridge.registerLazyCallableModule('Systrace', () =>
require('../Performance/Systrace'),
);
BatchedBridge.registerLazyCallableModule('JSTimers', () =>
require('./Timers/JSTimers'),
);
BatchedBridge.registerLazyCallableModule('HeapCapture', () =>
require('../HeapCapture/HeapCapture'),
);
BatchedBridge.registerLazyCallableModule('SamplingProfiler', () =>
require('../Performance/SamplingProfiler'),
);
BatchedBridge.registerLazyCallableModule('RCTLog', () =>
require('../Utilities/RCTLog'),
);
BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () =>
require('../EventEmitter/RCTDeviceEventEmitter'),
);
BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () =>
require('../EventEmitter/RCTNativeAppEventEmitter'),
);
BatchedBridge.registerLazyCallableModule('GlobalPerformanceLogger', () =>
require('../Utilities/GlobalPerformanceLogger'),
);
BatchedBridge.registerLazyCallableModule('JSDevSupportModule', () =>
require('../Utilities/JSDevSupportModule'),
);
if (__DEV__ && !global.__RCTProfileIsProfiling) {
BatchedBridge.registerCallableModule(
'HMRClient',
require('../Utilities/HMRClient'),
);
} else {
BatchedBridge.registerCallableModule(
'HMRClient',
require('../Utilities/HMRClientProdShim'),
);
}
}