Don't redbox on startup if Metro is not running

Summary:
This fixes a problem that occurs when:

1. You run an Android app with Fast Refresh on
2. Kill the app
3. Start the app again

We used to redbox (on Android only). This is probably because we are missing some check on the native side, and we try to enable the socket anyway.

We could potentially fix this on the native side. But also, there's no good reason why this code needs to ever throw an error if Fast Refresh is disabled.

So I'm unifying it with the existing code path for other Fast Refresh errors. They are ignored when it's off, shown as yellowboxes when it's on, and shown as redboxes if you intentionally try to turn it off and on again.

I'm also adding core to prevent logging more than one Fast Refresh warning. Since they're not super actionable and usually indicate the same problem (e.g. Metro not running). The earliest one wins.

Reviewed By: rickhanlonii

Differential Revision: D16286232

fbshipit-source-id: bf3960f11c767a2352b1282d46950e4ba9e5031d
This commit is contained in:
Dan Abramov 2019-07-17 06:17:21 -07:00 коммит произвёл Facebook Github Bot
Родитель e9640aeeb2
Коммит 8e6f2f289b
1 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -133,7 +133,7 @@ URL: ${host}:${port}
Error: ${e.message}`;
throw new Error(error);
setHMRUnavailableReason(error);
});
let didFinishInitialUpdate = false;
@ -229,7 +229,10 @@ Error: ${e.message}`;
function setHMRUnavailableReason(reason) {
invariant(hmrClient, 'Expected HMRClient.setup() call at startup.');
if (hmrUnavailableReason !== null) {
// Don't show more than one warning.
return;
}
hmrUnavailableReason = reason;
if (hmrClient.shouldApplyUpdates) {
// If HMR is currently enabled, show a warning.