From c787866d644be4c8d30bb17c237a50fdd6e1a82d Mon Sep 17 00:00:00 2001 From: Alexandre Kirszenberg Date: Mon, 12 Nov 2018 08:47:02 -0800 Subject: [PATCH] Clearer HMR error messages Summary: GraphNotFoundError: When the user moves the app to the background on Android, restarts the Metro server and reopens the app, since the client hasn't requested either a delta or a bundle, the graph cache of the server is empty and thus we can't compute an update for the client (what if changes happened when the metro server was down?). RevisionNotFoundError: I didn't manage to reproduce that one. It could happen if two clients live side-by-side, requesting the exact same bundle. In the future, if we want to handle that case, we'll need to manage a list of clients listening to a single graph so that we don't try to update the same graph multiple times for a single file change. Disconnection: Same as GraphNotFoundError, but happens when the user moves the app to the background on iOS. Reviewed By: mjesun Differential Revision: D12960939 fbshipit-source-id: 5ac1dc7fd12bad5e0ee8dfa5a21c112773454ee5 --- Libraries/Utilities/HMRClient.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Libraries/Utilities/HMRClient.js b/Libraries/Utilities/HMRClient.js index c4b379913acd73..d24cd4c46035ef 100644 --- a/Libraries/Utilities/HMRClient.js +++ b/Libraries/Utilities/HMRClient.js @@ -89,7 +89,27 @@ Error: ${e.message}`; hmrClient.on('error', data => { HMRLoadingView.hide(); - throw new Error(`${data.type} ${data.message}`); + + if (data.type === 'GraphNotFoundError') { + hmrClient.disable(); + throw new Error( + 'The packager server has restarted since the last Hot update. Hot Reloading will be disabled until you reload the application.', + ); + } else if (data.type === 'RevisionNotFoundError') { + hmrClient.disable(); + throw new Error( + 'The packager server and the client are out of sync. Hot Reloading will be disabled until you reload the application.', + ); + } else { + throw new Error(`${data.type} ${data.message}`); + } + }); + + hmrClient.on('close', data => { + HMRLoadingView.hide(); + throw new Error( + 'Disconnected from the packager server. Hot Reloading will be disabled until you reload the application.', + ); }); hmrClient.enable();