diff --git a/packages/react-native/React/CoreModules/RCTRedBox.mm b/packages/react-native/React/CoreModules/RCTRedBox.mm index 822e17ab570baf..300a3e926f51af 100644 --- a/packages/react-native/React/CoreModules/RCTRedBox.mm +++ b/packages/react-native/React/CoreModules/RCTRedBox.mm @@ -274,7 +274,13 @@ - (void)dismiss - (void)reload { - [_actionDelegate reloadFromRedBoxController:self]; + if (_actionDelegate != nil) { + [_actionDelegate reloadFromRedBoxController:self]; + } else { + // In bridgeless mode `RCTRedBox` gets deallocted, need to notify listeners anyway. + RCTTriggerReloadCommandListeners(@"Redbox"); + [self dismiss]; + } } - (void)showExtraDataViewController diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index a123105a672ce1..59da7befb16f34 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -24,7 +24,9 @@ #import #import #import +#import #import +#import #import #import #import @@ -64,7 +66,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags) sRuntimeDiagnosticFlags = [flags copy]; } -@interface RCTInstance () +@interface RCTInstance () @end @implementation RCTInstance { @@ -339,6 +341,10 @@ - (void)_start if (RCTGetUseNativeViewConfigsInBridgelessMode()) { installLegacyUIManagerConstantsProviderBinding(runtime); } + + RCTExecuteOnMainQueue(^{ + RCTRegisterReloadCommandListener(self); + }); [strongSelf->_delegate instance:strongSelf didInitializeRuntime:runtime]; @@ -420,8 +426,13 @@ - (void)_loadJSBundle:(NSURL *)sourceURL } if (error) { - // TODO(T91461138): Properly address bundle loading errors. - RCTLogError(@"RCTInstance: Error while loading bundle: %@", error); + RCTRedBox *redBox = [strongSelf->_turboModuleManager moduleForName:"RedBox"]; + RCTExecuteOnMainQueue(^{ + [[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidFailToLoadNotification + object:self + userInfo:@{@"error" : error}]; + [redBox showErrorMessage:[error localizedDescription]]; + }); [strongSelf invalidate]; return; } @@ -490,4 +501,8 @@ - (void)_handleJSErrorMap:(facebook::react::MapBuffer)errorMap isFatal:errorMap.getBool(JSErrorHandlerKey::kIsFatal)]; } +- (void)didReceiveReloadCommand { + [self _loadJSBundle:[self->_bridgeModuleDecorator.bundleManager bundleURL]]; +} + @end