From 8b5ed7abdd7c454aa532abe5e9652388597f1113 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 23 Jul 2019 16:15:20 -0700 Subject: [PATCH] Fixing error on first mount should fall back to reload Summary: This updates `react-refresh` to 0.3.0 which brings a new feature: we can now detect if the root fails on _the initial mount_. In that case we currently can't recover with Fast Refresh because we don't know which element to retry mounting. (In the future, we can lift this limitation, but it would require more changes in React renderer.) Before this diff, after you fix an error on initial mount, you would see a blank screen (because nothing managed to mount). After this diff, after you fix an error on initial mount, you would fall back to a full reload. This diff doesn't affect errors on updates. We can recover from those, just like before. Reviewed By: cpojer Differential Revision: D16440836 fbshipit-source-id: 4a414202a9eab894acd7baa0525c25ff003dd323 --- Libraries/Core/setUpReactRefresh.js | 8 +++++++- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Libraries/Core/setUpReactRefresh.js b/Libraries/Core/setUpReactRefresh.js index 463123ee82..062171a9b0 100644 --- a/Libraries/Core/setUpReactRefresh.js +++ b/Libraries/Core/setUpReactRefresh.js @@ -35,7 +35,13 @@ if (__DEV__) { register: ReactRefreshRuntime.register, - performReactRefresh: ReactRefreshRuntime.performReactRefresh, + performReactRefresh() { + if (ReactRefreshRuntime.hasUnrecoverableErrors()) { + NativeDevSettings.reload(); + return; + } + ReactRefreshRuntime.performReactRefresh(); + }, }; (require: any).Refresh = Refresh; diff --git a/package.json b/package.json index c8dcdf992a..23c17b82d6 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "promise": "^7.1.1", "prop-types": "^15.7.2", "react-devtools-core": "^3.6.2", - "react-refresh": "^0.2.0", + "react-refresh": "^0.3.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.14.0", "stacktrace-parser": "^0.1.3", diff --git a/yarn.lock b/yarn.lock index 4fa2e5aa65..a0a3e05b71 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5926,10 +5926,10 @@ react-proxy@^1.1.7: lodash "^4.6.1" react-deep-force-update "^1.0.0" -react-refresh@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.2.0.tgz#f0cff375e8f75dea7133a847a1b40cf5c073dd0d" - integrity sha512-ITw8t/HOFNose2yf1y9pPFSSeB9ISOq2JdHpuZvj/Qb+iSsLml8GkkHdDlURzieO7B3dFDtMrrneZLl3N5z/hg== +react-refresh@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.3.0.tgz#dcbf3c1f2fd2f06dc553c4682cf4ae8e72413b05" + integrity sha512-Q4VkuukL/FMo01lifODwMPl6/Pa1OUDJqBEHNw8aLnWIoNsX2BmzRUG+5V7bAPLRXw/fWHNFOmcwRqFfGKrpBw== react-test-renderer@16.8.6: version "16.8.6"