Skip to content

Commit

Permalink
fix: RCTRedBox not appearing in Bridgeless when metro is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Feb 22, 2024
1 parent 4def40e commit d32f1a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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, 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 @@ -64,7 +66,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
sRuntimeDiagnosticFlags = [flags copy];
}

@interface RCTInstance () <RCTTurboModuleManagerDelegate, RCTTurboModuleManagerRuntimeHandler>
@interface RCTInstance () <RCTTurboModuleManagerDelegate, RCTTurboModuleManagerRuntimeHandler, RCTReloadListener>
@end

@implementation RCTInstance {
Expand Down Expand Up @@ -339,6 +341,10 @@ - (void)_start
if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
installLegacyUIManagerConstantsProviderBinding(runtime);
}

RCTExecuteOnMainQueue(^{
RCTRegisterReloadCommandListener(self);
});

[strongSelf->_delegate instance:strongSelf didInitializeRuntime:runtime];

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -490,4 +501,8 @@ - (void)_handleJSErrorMap:(facebook::react::MapBuffer)errorMap
isFatal:errorMap.getBool(JSErrorHandlerKey::kIsFatal)];
}

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

@end

0 comments on commit d32f1a9

Please sign in to comment.