Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/react-native/React/CoreModules/RCTRedBox.mm
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,13 @@ - (void)dismiss

- (void)reload
{
[_actionDelegate reloadFromRedBoxController:self];
if (_actionDelegate != nil) {
[_actionDelegate reloadFromRedBoxController:self];
} else {
// In bridgeless mode `RCTRedBox` gets deallocted, we need to notify listeners anyway.
RCTTriggerReloadCommandListeners(@"Redbox");
[self dismiss];
}
}

- (void)showExtraDataViewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#import <React/RCTEventDispatcherProtocol.h>
#import <React/RCTFollyConvert.h>
#import <React/RCTJavaScriptLoader.h>
#import <React/RCTReloadCommand.h>
#import <React/RCTLog.h>
#import <React/RCTRedBox.h>
#import <React/RCTLogBox.h>
#import <React/RCTModuleData.h>
#import <React/RCTPerformanceLogger.h>
Expand Down Expand Up @@ -121,11 +123,18 @@ - (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
[weakSelf callFunctionOnJSModule:moduleName method:methodName args:args];
}];
}

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_notifyEventDispatcherObserversOfEvent_DEPRECATED:)
name:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED"
object:nil];

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self
selector:@selector(_notifyEventDispatcherObserversOfEvent_DEPRECATED:)
name:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED"
object:nil];

[defaultCenter addObserver:self
selector:@selector(didReceiveReloadCommand)
name:RCTTriggerReloadCommandNotification
object:nil];

[self _start];
}
Expand Down Expand Up @@ -389,6 +398,27 @@ - (void)_attachBridgelessAPIsToModule:(id<RCTTurboModule>)module
}
}

- (void)handleError:(NSError *)error
{
if (!_valid) {
return;
}

RCTRedBox *redBox = [self->_turboModuleManager moduleForName:"RedBox"];

RCTExecuteOnMainQueue(^{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidFailToLoadNotification
object:self
userInfo:@{@"error": error}];

// TODO: Attach error raw stack RCTJSRawStackTraceKey
[redBox showErrorMessage:[error localizedDescription]];

RCTFatal(error);
});
}


- (void)_loadJSBundle:(NSURL *)sourceURL
{
#if RCT_DEV_MENU && __has_include(<React/RCTDevLoadingViewProtocol.h>)
Expand Down Expand Up @@ -420,8 +450,7 @@ - (void)_loadJSBundle:(NSURL *)sourceURL
}

if (error) {
// TODO(T91461138): Properly address bundle loading errors.
RCTLogError(@"RCTInstance: Error while loading bundle: %@", error);
[strongSelf handleError:error];
[strongSelf invalidate];
return;
}
Expand All @@ -446,6 +475,7 @@ - (void)_loadScriptFromSource:(RCTSource *)source
const auto *url = deriveSourceURL(source.url).UTF8String;
_reactInstance->loadScript(std::move(script), url);
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil];


if (_onInitialBundleLoad) {
_onInitialBundleLoad();
Expand Down Expand Up @@ -490,4 +520,8 @@ - (void)_handleJSErrorMap:(facebook::react::MapBuffer)errorMap
isFatal:errorMap.getBool(JSErrorHandlerKey::kIsFatal)];
}

- (void)didReceiveReloadCommand {
[self _loadJSBundle:[self->_bridgeModuleDecorator.bundleManager bundleURL]];
}

Comment on lines +523 to +526
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@okwasniewski, why did you end up registering the RCTInstance as a reload command listener here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When clicking Reload on the redbox nothing was happening

@end