From 845e9eaafb08b4ca87a9987e840798e0ba011676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Mon, 14 Sep 2020 17:42:31 -0700 Subject: [PATCH] Fix for loading state of Fast Refresh from user defaults (#29880) Summary: Disabling Fast Refresh won't be persisted when restarting the app. I believe this regressed with https://github.com/facebook/react-native/commit/824e1711172d14a9373209bbae63d1ae50601625. In this commit `HMRClient.setup` will always be called with `enabled` being set true. This PR loads the _enabled_ state from the user defaults (as it was done before). ## Changelog [iOS] [Fixed] - Enable Fast Refresh gets persisted across app launches Pull Request resolved: https://github.com/facebook/react-native/pull/29880 Test Plan: Without this change Fast Refresh is enabled on every app restart. Tested with this change: - Disabling Fast Refresh - Restarting App -> Fast Refresh still disabled - Enabled Fast Refresh again - Restarting App -> Fast Refresh still enabled again Reviewed By: sammy-SC Differential Revision: D23686435 Pulled By: PeteTheHeat fbshipit-source-id: 42c31b22060d3dc4b1d4cb8f41792b303fc7fce8 --- React/CoreModules/RCTDevSettings.mm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/React/CoreModules/RCTDevSettings.mm b/React/CoreModules/RCTDevSettings.mm index b84d4e3114233e..50d9cd0cde8447 100644 --- a/React/CoreModules/RCTDevSettings.mm +++ b/React/CoreModules/RCTDevSettings.mm @@ -405,17 +405,18 @@ - (void)addHandler:(id)handler forPackagerMethod:(NSStr - (void)setupHMRClientWithBundleURL:(NSURL *)bundleURL { - if (bundleURL && !bundleURL.fileURL) { // isHotLoadingAvailable check + if (bundleURL && !bundleURL.fileURL) { NSString *const path = [bundleURL.path substringFromIndex:1]; // Strip initial slash. NSString *const host = bundleURL.host; NSNumber *const port = bundleURL.port; + BOOL isHotLoadingEnabled = self.isHotLoadingEnabled; if (self.bridge) { [self.bridge enqueueJSCall:@"HMRClient" method:@"setup" - args:@[ @"ios", path, host, RCTNullIfNil(port), @(YES) ] + args:@[ @"ios", path, host, RCTNullIfNil(port), @(isHotLoadingEnabled) ] completion:NULL]; } else { - self.invokeJS(@"HMRClient", @"setup", @[ @"ios", path, host, RCTNullIfNil(port), @(YES) ]); + self.invokeJS(@"HMRClient", @"setup", @[ @"ios", path, host, RCTNullIfNil(port), @(isHotLoadingEnabled) ]); } } }