mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
08bfdfad67
Summary:
Since we always create `module.hot` objects, the `module.hot` checks were unnecessary. They give a false impression that we're checking for a Hot Reloading mode. However, they're just Flow refinements and always exist in DEV. I made that explicit by throwing early.
Similarly, I removed a `module.hot` check inside `setupReactRefresh`, as it is always truish in DEV.
Finally, I'm adding a new mechanism as an escape hatch. It lets you do:
```
if (__DEV__) {
require.Refresh.forceFullRefresh = true;
}
```
in your entry point and opt into full refreshes on every edit. This sounds similar to "Reload-on-Save". That is because in the next diff, I plan to remove "Reload-on-Save" from user-visible options (but it'll stay for automated workflows).
So this workaround is intended for people who for one reason or another don't want to opt into Hot Reloading as an alternative. We'll need to talk to them and find out why.
Reviewed By: rickhanlonii
Differential Revision: D15958475
fbshipit-source-id: 674187ddf86a4e286dfae28f4182555a8b5d7396
52 lines
1.3 KiB
JavaScript
52 lines
1.3 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
|
|
* @format
|
|
*/
|
|
'use strict';
|
|
|
|
if (__DEV__) {
|
|
const NativeDevSettings = require('../NativeModules/specs/NativeDevSettings')
|
|
.default;
|
|
|
|
if (typeof NativeDevSettings.reload !== 'function') {
|
|
throw new Error('Could not find the reload() implementation.');
|
|
}
|
|
|
|
// This needs to run before the renderer initializes.
|
|
const ReactRefreshRuntime = require('react-refresh/runtime');
|
|
ReactRefreshRuntime.injectIntoGlobalHook(global);
|
|
|
|
const Refresh = {
|
|
// This can be set from the app as a workaround
|
|
// if you really want a full reload on every change:
|
|
// if (__DEV__) require.Refresh.forceFullRefresh = true;
|
|
forceFullRefresh: false,
|
|
|
|
performFullRefresh() {
|
|
NativeDevSettings.reload();
|
|
},
|
|
|
|
createSignatureFunctionForTransform:
|
|
ReactRefreshRuntime.createSignatureFunctionForTransform,
|
|
|
|
isLikelyComponentType: ReactRefreshRuntime.isLikelyComponentType,
|
|
|
|
register: ReactRefreshRuntime.register,
|
|
|
|
performReactRefresh() {
|
|
if (Refresh.forceFullRefresh) {
|
|
NativeDevSettings.reload();
|
|
} else {
|
|
ReactRefreshRuntime.performReactRefresh();
|
|
}
|
|
},
|
|
};
|
|
|
|
(require: any).Refresh = Refresh;
|
|
}
|