mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Don't show warnings unless we managed to connect
Summary: On iOS we don't call `HMRClient.setup()` when Metro is off. So we don't bump into any odd cases. But on Android, we do call `HMRClient.setup()` even if Metro is off. As a result, we might show a warning about Metro not running to a native engineer who doesn't care (because they don't intend to work on JS). We could fix this on Android on the native side. And we probably should. But we can also strengthen it here. The idea is that we should only show warnings about disconnecting from Metro *if we ever managed to successfully connect in the first place*. Otherwise, we can assume that you didn't mean to connect. If the user is trying to determine the source of the problem, they can still do a full Refresh (on iOS this will show a message about needing Metro, on Android it would show a redbox). So this diff makes the disconnected behavior closer to how it worked before Fast Refresh. Reviewed By: sahrens Differential Revision: D16460439 fbshipit-source-id: bf962ff34c25d9734d9668dd583591acacb98253
This commit is contained in:
committed by
Facebook Github Bot
parent
2a3ac0429b
commit
5e960e30eb
@@ -22,6 +22,7 @@ const pendingEntryPoints = [];
|
||||
let hmrClient = null;
|
||||
let hmrUnavailableReason: string | null = null;
|
||||
let currentCompileErrorMessage: string | null = null;
|
||||
let didConnect: boolean = false;
|
||||
|
||||
type LogLevel =
|
||||
| 'trace'
|
||||
@@ -169,6 +170,8 @@ Error: ${e.message}`;
|
||||
|
||||
client.on('update-start', ({isInitialUpdate}) => {
|
||||
currentCompileErrorMessage = null;
|
||||
didConnect = true;
|
||||
|
||||
if (client.isEnabled() && !isInitialUpdate) {
|
||||
LoadingView.showMessage('Refreshing...', 'refresh');
|
||||
}
|
||||
@@ -229,8 +232,11 @@ function setHMRUnavailableReason(reason) {
|
||||
return;
|
||||
}
|
||||
hmrUnavailableReason = reason;
|
||||
if (hmrClient.isEnabled()) {
|
||||
// If HMR is currently enabled, show a warning.
|
||||
|
||||
// We only want to show a warning if Fast Refresh is on *and* if we ever
|
||||
// previously managed to connect successfully. We don't want to show
|
||||
// the warning to native engineers who use cached bundles without Metro.
|
||||
if (hmrClient.isEnabled() && didConnect) {
|
||||
console.warn(reason);
|
||||
// (Not using the `warning` module to prevent a Buck cycle.)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user