Skip to content

Commit ffe2306

Browse files
Peter Arganyfacebook-github-bot
Peter Argany
authored andcommitted
Deprecate bridge reload API [1/n]
Summary: Testing the waters with an idea for unifying RN lifecycle with/without bridge. ### Motivation/Background RN bridge is being reloaded from [several different places](https://fburl.com/codesearch/ae3zeatt). When this happens, the bridge does a bunch of things: 1. Post `RCTBridgeWillReloadNotification` (RCTSurfacePresenter listens to this and reloads) 2. Invalidate batched bridge, which does: a. invalidate display link b. post `RCTBridgeWillInvalidateModules/RCTBridgeDidInvalidateModules` (TurboModuleManager listens to this and reloads modules) c. clear js thread state d. clear some local caches 3. Set up (reload bundle and batched bridge) In a bridgeless world, there isn't one thing which owns all these peices of infra, and can reload them. ### Plan Use `RCTReloadCommand` to handle reloads. This light class previously only handled CMD+R. The new workflow looks like this: 1. Anything which cares about reloads can register itself as a listener. (RCTBridge, RCTSurfacePresenter, TurboModuleManager...) 2. Anything that previously called `bridge reload` now calls `RCTTriggerReloadCommandListeners`. 3. Delete old notifications ### Alternate Plan Use yet another NSNotification. I like `RCTReloadCommand` better. ### Unknowns Looks like we log the reason for bridge reloading [here](https://fburl.com/diffusion/lc9jj8la), do we want to save this behaviour? Does anyone look at why bridge is being reloaded cc/Rick? If so, I can add back that functionality to `RCTReloadCommand`. It should be possible to customize the order/priority of what gets reloaded first. There may be some racy behaviour that I haven't thought about yet. Changelog: [iOS][Deprecated] Deprecate [bridge reload] API - prefer RCTReloadCommand Reviewed By: shergin Differential Revision: D17869635 fbshipit-source-id: 81f39eaa2c3ce08ea1bc6f2193684c2630d81a2d
1 parent 35b8b06 commit ffe2306

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

React/Base/RCTBridge.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ RCT_EXTERN void RCTEnableTurboModule(BOOL enabled);
271271
/**
272272
* Reload the bundle and reset executor & modules. Safe to call from any thread.
273273
*/
274-
- (void)reload __deprecated_msg("Call reloadWithReason instead");
274+
- (void)reload __deprecated_msg("Use RCTReloadCommand instead");
275275

276276
/**
277277
* Reload the bundle and reset executor & modules. Safe to call from any thread.
278278
*/
279-
- (void)reloadWithReason:(NSString *)reason;
279+
- (void)reloadWithReason:(NSString *)reason __deprecated_msg("Use RCTReloadCommand instead");
280280

281281
/**
282282
* Handle notifications for a fast refresh. Safe to call from any thread.
@@ -286,7 +286,7 @@ RCT_EXTERN void RCTEnableTurboModule(BOOL enabled);
286286
/**
287287
* Inform the bridge, and anything subscribing to it, that it should reload.
288288
*/
289-
- (void)requestReload __deprecated_msg("Call reloadWithReason instead");
289+
- (void)requestReload __deprecated_msg("Use RCTReloadCommand instead");
290290

291291
/**
292292
* Says whether bridge has started receiving calls from javascript.

React/Base/RCTBridge.m

+7-1
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,16 @@ - (BOOL)moduleIsInitialized:(Class)moduleClass
294294
}
295295

296296
/**
297-
* Legacy reload, please use reloadWithReason and provide a reason for stats.
297+
* DEPRECATED - please use RCTReloadCommand.
298298
*/
299299
- (void)reload
300300
{
301301
[self reloadWithReason:@"Unknown from bridge"];
302302
}
303303

304+
/**
305+
* DEPRECATED - please use RCTReloadCommand.
306+
*/
304307
- (void)reloadWithReason:(NSString *)reason
305308
{
306309
#if RCT_ENABLE_INSPECTOR && !TARGET_OS_UIKITFORMAC
@@ -328,6 +331,9 @@ - (void)onFastRefresh
328331
[[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeFastRefreshNotification object:self];
329332
}
330333

334+
/**
335+
* DEPRECATED - please use RCTReloadCommand.
336+
*/
331337
- (void)requestReload
332338
{
333339
[self reloadWithReason:@"Requested from bridge"];

React/Base/RCTReloadCommand.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@
99

1010
#import <React/RCTDefines.h>
1111

12+
/**
13+
* A protocol which should be conformed to in order to be notified of RN reload events. These events can be
14+
* created by CMD+R or dev menu during development, or anywhere the trigger is exposed to JS.
15+
* The listener must also register itself using the method below.
16+
*/
1217
@protocol RCTReloadListener
1318
- (void)didReceiveReloadCommand;
1419
@end
1520

16-
/** Registers a weakly-held observer of the Command+R reload key command. */
21+
/**
22+
* Registers a weakly-held observer of RN reload events.
23+
*/
1724
RCT_EXTERN void RCTRegisterReloadCommandListener(id<RCTReloadListener> listener);
1825

19-
/** Triggers a reload for all current listeners. You shouldn't need to use this directly in most cases. */
26+
/**
27+
* Triggers a reload for all current listeners.
28+
*/
2029
RCT_EXTERN void RCTTriggerReloadCommandListeners(void);

0 commit comments

Comments
 (0)