From 19d04a312bf4221cd26beff6d0da6dd296a28cd0 Mon Sep 17 00:00:00 2001 From: Alexander Nikiforov Date: Tue, 15 Jan 2019 02:04:19 -0800 Subject: [PATCH] iOS: Clear `Linking.getInitialURL` during bridge reload (#22659) Summary: On iOS platform, RN retains launchOptions dictionary after bridge reload which can lead to unexpected consequences to a developer. The app will receive the same value for `Linking.getInitialURL` during initial launch and during bridge reload. Here's an example from our application. We use deeplinks via custom URL scheme so a user can open the app via link. Also, we reload the bridge when a user signs out. So if a user opens the app via URL, logs out, and a second user logs into the app, the app will behave as though the second user launched the app via the same deeplink. Because reload destroys the JS engine, there's nowhere for our app to remember that it already handled the deeplink activation. On iOS Linking.getInitialURL() gets URL from the _launchOptions dictionary, so by setting it to nil we prevent retention of initialURL after reload. This change makes iOS's behavior consistent with Android's. On Android, the launch URL is stored on the `Intent` and reloading the app involves creating a new `Intent`. Consequently, the launch URL is dropped as desired during the reload process. Pull Request resolved: https://github.com/facebook/react-native/pull/22659 Differential Revision: D13564251 Pulled By: cpojer fbshipit-source-id: 4c6d81f1775eb3c41b100582436f1c0f1ee6dc36 --- React/Base/RCTBridge.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 046925eef4ca69..08adf5188f8d45 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -288,6 +288,8 @@ - (void)reload */ dispatch_async(dispatch_get_main_queue(), ^{ [self invalidate]; + // Reload is a special case, do not preserve launchOptions and treat reload as a fresh start + self->_launchOptions = nil; [self setUp]; }); }