Add and use reloadWithReason to iOS
Summary: This diff adds a new reloading method reloadWithReason that allows callers to provide a reason for why a reload was requested. This reason is useful for understanding why users are reloading, and why Fast Refresh is bailing out to a full reload. I also updated the places we reload with the reasons listed below. **Standard native reasons:** - Redbox - Command - Global hotkey - Profiling controls - Dev menu - reload - Dev menu - reset to default - Dev menu - apply changes **From JavaScript (added in a later diff):** - Fast Refresh - Unrecoverable - Fast Refresh - No root boundary - Fast Refresh - Invalidated boundary - Fast Refresh - Invalidated root boundary **Misc reasons and fallback for when a reason is unavailable:** - Unknown from JS - Uncategorized from JS - Unknown from bridge - Unknown from cxx bridge - Requested from bridge - Custom executor class reset Reviewed By: cpojer Differential Revision: D17499339 fbshipit-source-id: 12a21ffa05708c9b921d93911f190cdffc5c78d5
This commit is contained in:
Родитель
59b96fe9a3
Коммит
2ccc8fbc28
|
@ -254,12 +254,17 @@ RCT_EXTERN void RCTEnableTurboModule(BOOL enabled);
|
|||
/**
|
||||
* Reload the bundle and reset executor & modules. Safe to call from any thread.
|
||||
*/
|
||||
- (void)reload;
|
||||
- (void)reload __deprecated_msg("Call reloadWithReason instead");
|
||||
|
||||
/**
|
||||
* Reload the bundle and reset executor & modules. Safe to call from any thread.
|
||||
*/
|
||||
- (void)reloadWithReason:(NSString *)reason;
|
||||
|
||||
/**
|
||||
* Inform the bridge, and anything subscribing to it, that it should reload.
|
||||
*/
|
||||
- (void)requestReload __deprecated_msg("Call reload instead");
|
||||
- (void)requestReload __deprecated_msg("Call reloadWithReason instead");
|
||||
|
||||
/**
|
||||
* Says whether bridge has started receiving calls from javascript.
|
||||
|
|
|
@ -244,7 +244,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
|
||||
- (void)didReceiveReloadCommand
|
||||
{
|
||||
[self reload];
|
||||
[self reloadWithReason:@"Command"];
|
||||
}
|
||||
|
||||
- (NSArray<Class> *)moduleClasses
|
||||
|
@ -290,14 +290,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
return [self.batchedBridge moduleIsInitialized:moduleClass];
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy reload, please use reloadWithReason and provide a reason for stats.
|
||||
*/
|
||||
- (void)reload
|
||||
{
|
||||
[self reloadWithReason:@"Unknown from bridge"];
|
||||
}
|
||||
|
||||
- (void)reloadWithReason:(NSString *)reason
|
||||
{
|
||||
#if RCT_ENABLE_INSPECTOR && !TARGET_OS_UIKITFORMAC
|
||||
// Disable debugger to resume the JsVM & avoid thread locks while reloading
|
||||
[RCTInspectorDevServerHelper disableDebugger];
|
||||
#endif
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self userInfo:@{@"reason": reason} ];
|
||||
|
||||
/**
|
||||
* Any thread
|
||||
|
@ -314,7 +322,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
|
||||
- (void)requestReload
|
||||
{
|
||||
[self reload];
|
||||
[self reloadWithReason:@"Requested from bridge"];
|
||||
}
|
||||
|
||||
- (Class)bridgeClass
|
||||
|
|
|
@ -487,7 +487,7 @@ struct RCTInstanceCallback : public InstanceCallback {
|
|||
}
|
||||
return moduleData.instance;
|
||||
}
|
||||
|
||||
|
||||
static NSSet<NSString *> *ignoredModuleLoadFailures = [NSSet setWithArray: @[@"UIManager"]];
|
||||
|
||||
// Module may not be loaded yet, so attempt to force load it here.
|
||||
|
@ -1009,7 +1009,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
|||
if (!_valid) {
|
||||
RCTLogWarn(@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", self);
|
||||
}
|
||||
[_parentBridge reload];
|
||||
[_parentBridge reloadWithReason:@"Unknown from cxx bridge"];
|
||||
}
|
||||
|
||||
- (void)reloadWithReason:(NSString *)reason
|
||||
{
|
||||
if (!_valid) {
|
||||
RCTLogWarn(@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", self);
|
||||
}
|
||||
[_parentBridge reloadWithReason:reason];
|
||||
}
|
||||
|
||||
- (Class)executorClass
|
||||
|
|
|
@ -200,7 +200,7 @@ RCT_EXPORT_MODULE()
|
|||
[[RCTBundleURLProvider sharedSettings] resetToDefaults];
|
||||
self->_bridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackResource:nil
|
||||
fallbackExtension:nil];
|
||||
[self->_bridge reload];
|
||||
[self->_bridge reloadWithReason:@"Dev menu - reset to default"];
|
||||
}
|
||||
|
||||
- (NSArray<RCTDevMenuItem *> *)_menuItemsToPresent
|
||||
|
@ -214,7 +214,7 @@ RCT_EXPORT_MODULE()
|
|||
|
||||
[items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload"
|
||||
handler:^{
|
||||
[bridge reload];
|
||||
[bridge reloadWithReason:@"Dev menu - reload"];
|
||||
}]];
|
||||
|
||||
if (!devSettings.isProfilingEnabled) {
|
||||
|
@ -373,7 +373,7 @@ RCT_EXPORT_MODULE()
|
|||
fallbackResource:nil]
|
||||
: [strongBridge.delegate sourceURLForBridge:strongBridge];
|
||||
strongBridge.bundleURL = bundleURL;
|
||||
[strongBridge reload];
|
||||
[strongBridge reloadWithReason:@"Dev menu - apply changes"];
|
||||
}
|
||||
}]];
|
||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Reset to Default"
|
||||
|
@ -455,7 +455,7 @@ RCT_EXPORT_METHOD(show)
|
|||
RCT_EXPORT_METHOD(reload)
|
||||
{
|
||||
WARN_DEPRECATED_DEV_MENU_EXPORT();
|
||||
[_bridge reload];
|
||||
[_bridge reloadWithReason:@"Unknown from JS"];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(debugRemotely : (BOOL)enableDebug)
|
||||
|
|
|
@ -161,7 +161,7 @@ RCT_EXPORT_MODULE()
|
|||
if (params != (id)kCFNull && [params[@"debug"] boolValue]) {
|
||||
weakBridge.executorClass = objc_lookUpClass("RCTWebSocketExecutor");
|
||||
}
|
||||
[weakBridge reload];
|
||||
[weakBridge reloadWithReason:@"Global hotkey"];
|
||||
}
|
||||
queue:dispatch_get_main_queue()
|
||||
forMethod:@"reload"];
|
||||
|
@ -236,7 +236,13 @@ RCT_EXPORT_MODULE()
|
|||
|
||||
RCT_EXPORT_METHOD(reload)
|
||||
{
|
||||
[self.bridge reload];
|
||||
[self.bridge reloadWithReason:@"Unknown From JS"];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(reloadWithReason : (NSString *) reason)
|
||||
{
|
||||
[self.bridge reloadWithReason:reason];
|
||||
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setIsShakeToShowDevMenuEnabled : (BOOL)enabled)
|
||||
|
@ -369,7 +375,7 @@ RCT_EXPORT_METHOD(addMenuItem:(NSString *)title)
|
|||
}
|
||||
|
||||
self.bridge.executorClass = executorClass;
|
||||
[self.bridge reload];
|
||||
[self.bridge reloadWithReason:@"Custom executor class reset"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -442,6 +448,9 @@ RCT_EXPORT_METHOD(addMenuItem:(NSString *)title)
|
|||
- (void)reload
|
||||
{
|
||||
}
|
||||
- (void)reloadWithReason
|
||||
{
|
||||
}
|
||||
- (void)toggleElementInspector
|
||||
{
|
||||
}
|
||||
|
|
|
@ -607,7 +607,7 @@ RCT_EXPORT_METHOD(dismiss)
|
|||
if (_overrideReloadAction) {
|
||||
_overrideReloadAction();
|
||||
} else {
|
||||
[_bridge reload];
|
||||
[_bridge reloadWithReason:@"Redbox"];
|
||||
}
|
||||
[self dismiss];
|
||||
}
|
||||
|
|
|
@ -372,7 +372,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge)
|
|||
|
||||
+ (void)reload
|
||||
{
|
||||
[RCTProfilingBridge() reload];
|
||||
[RCTProfilingBridge() reloadWithReason:@"Profiling controls"];
|
||||
}
|
||||
|
||||
+ (void)toggle:(UIButton *)target
|
||||
|
|
Загрузка…
Ссылка в новой задаче