Skip to content

Commit 4148746

Browse files
vzaidmanfacebook-github-bot
authored andcommitted
add disconnection message (#53883)
Summary: Pull Request resolved: #53883 Changelog: [General][Added] - new banner added to indicate that Fast Refresh has lost connection, and that the app needs to be restarted to reconnect When HMR were getting disconnected, we were not giving any indication for the user. This lead to situations were the connection is re-established, but HMR is still disconnected, which is unexpected for users. Instead, raise a banner hinting the user to reload the app to reconnect. Reviewed By: huntie Differential Revision: D82726853 fbshipit-source-id: d5f264547b2af89e9dc2a9046d063efe1145d690
1 parent 34f7137 commit 4148746

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

packages/react-native/Libraries/Utilities/DevLoadingView.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,37 @@ import NativeDevLoadingView from './NativeDevLoadingView';
1414

1515
const COLOR_SCHEME = {
1616
dark: {
17+
load: {
18+
backgroundColor: '#fafafa',
19+
textColor: '#242526',
20+
},
1721
refresh: {
1822
backgroundColor: '#2584e8',
1923
textColor: '#ffffff',
2024
},
21-
load: {
22-
backgroundColor: '#fafafa',
23-
textColor: '#242526',
25+
error: {
26+
backgroundColor: '#1065AF',
27+
textColor: '#ffffff',
2428
},
2529
},
2630
default: {
31+
load: {
32+
backgroundColor: '#404040',
33+
textColor: '#ffffff',
34+
},
2735
refresh: {
2836
backgroundColor: '#2584e8',
2937
textColor: '#ffffff',
3038
},
31-
load: {
32-
backgroundColor: '#404040',
39+
error: {
40+
backgroundColor: '#1065AF',
3341
textColor: '#ffffff',
3442
},
3543
},
3644
};
3745

3846
export default {
39-
showMessage(message: string, type: 'load' | 'refresh') {
47+
showMessage(message: string, type: 'load' | 'refresh' | 'error') {
4048
if (NativeDevLoadingView) {
4149
const colorScheme =
4250
getColorScheme() === 'dark' ? COLOR_SCHEME.dark : COLOR_SCHEME.default;

packages/react-native/Libraries/Utilities/HMRClient.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ Error: ${e.message}`;
232232
});
233233

234234
client.on('error', data => {
235-
DevLoadingView.hide();
236-
237235
if (data.type === 'GraphNotFoundError') {
238236
client.close();
239237
setHMRUnavailableReason(
@@ -253,8 +251,6 @@ Error: ${e.message}`;
253251
});
254252

255253
client.on('close', closeEvent => {
256-
DevLoadingView.hide();
257-
258254
// https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1
259255
// https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5
260256
const isNormalOrUnsetCloseReason =
@@ -296,10 +292,17 @@ function setHMRUnavailableReason(reason: string) {
296292
}
297293
hmrUnavailableReason = reason;
298294

295+
const DevLoadingView = require('./DevLoadingView').default;
296+
DevLoadingView.hide();
297+
299298
// We only want to show a warning if Fast Refresh is on *and* if we ever
300299
// previously managed to connect successfully. We don't want to show
301300
// the warning to native engineers who use cached bundles without Metro.
302301
if (hmrClient.isEnabled() && didConnect) {
302+
DevLoadingView.showMessage(
303+
'Fast Refresh disconnected. Reload app to reconnect.',
304+
'error',
305+
);
303306
console.warn(reason);
304307
// (Not using the `warning` module to prevent a Buck cycle.)
305308
}

0 commit comments

Comments
 (0)