-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[0.65] [iOS] Redbox displayed as well as LogBox #32106
Comments
Shouldn't the RedBox be deprecated? |
@mrousavy RedBox is still needed for cases where the bundle fails to load, since LogBox has not yet loaded. RedBox display is instead handled in native code. |
Oh so the LogBox cannot be activated from native code? I tried to find an API for that to add LogBox (incl. stacktrace and source preview) support for Reanimated/VisionCamera Worklets, but seems like that's pretty difficult to achieve... |
@mrousavy LogBox is rendered in JS using react-native, but you can inject redbox/yellowbox from native if you really want to. Instance load registers That async from native triggers the equivalent of console.warn or console.log. |
These would likely all be considered private APIs though... So YMMV |
thanks nick! |
Today I was upgrading to 0.65.2 make it works but all console.errors trigger a fullScreen LogBox. There is any workaround or plan to fix this ? |
Also in the same position as @anthowm. Does anyone know if this is being looked at? |
@apamphilon By the moment we put this so we can go ahead with the upgrade don't know the full impact of put this
// @ts-ignore Disable error screen from console.error as we use it. console.reportErrorsAsExceptions = false; |
@anthowm This could work as a workaround for now although one thing to note with this is that it also disables LogBox for console.errors. |
I have the exact same issue, after 1 hour looking for solutions, it appears this issue is the only one trying to solve this. |
I am facing the same issue with 0.66. It would be nice to have a workaround. |
Just encountered this upgrading from RN 0.63.4 to 0.66.3 myself. Only seems to affect iOS. |
Oh, I forgot to post in here. I believe I've found the original cause for this issue and I've raised a PR for the fix: #32641 If you want to fix it locally, in advance of the PR being released, it's a one-line change you could use patch-package to apply. |
Thanks a lot @liamjones , created a patch for my project and it works perfectly well 👌 Nice job ! |
@liamjones Thanks for finding the cause and fixing it. I solved it with method swizzling. Since I do a lot of swizzling, this method was easy. Just add the code below to your project. // RCTExceptionsManager+FixBug.h
#import <React-Core/React/RCTExceptionsManager.h>
@interface RCTExceptionsManager (FixBug)
@end // RCTExceptionsManager+FixBug.m
#import "RCTExceptionsManager+FixBug.h"
#import <objc/message.h>
#import <React-Core/React/RCTRedBox.h>
@implementation RCTExceptionsManager (FixBug)
BOOL swizzle(Class __nonnull class, SEL __nonnull originalSelector, SEL __nonnull newSelector, id __nonnull block) {
if ([class instancesRespondToSelector:newSelector]) {
return YES;
}
Method originalMethod = class_getInstanceMethod(class, originalSelector);
IMP implementForNewSelector = imp_implementationWithBlock(block);
if (!class_addMethod(class, newSelector, implementForNewSelector, method_getTypeEncoding(originalMethod))) {
return NO;
}
Method newMethod = class_getInstanceMethod(class, newSelector);
if (class_addMethod(class, originalSelector, method_getImplementation(newMethod), method_getTypeEncoding(originalMethod))) {
class_replaceMethod(class, newSelector, method_getImplementation(originalMethod), method_getTypeEncoding(newMethod));
}
else {
method_exchangeImplementations(originalMethod, newMethod);
}
NSLog(@"Swizzled [%@] %@ -> %@", NSStringFromClass(class), NSStringFromSelector(originalSelector), NSStringFromSelector(newSelector));
return YES;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
+ (void)initialize {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL originSelector = @selector(updateExceptionMessage:stack:exceptionId:);
SEL swizzleSelector = @selector(swizzle_updateExceptionMessage:stack:exceptionId:);
swizzle([RCTExceptionsManager class], originSelector, swizzleSelector, ^(RCTExceptionsManager *manager, NSString *message, NSArray<NSDictionary *> *stack, double exceptionId) {
RCTRedBox *redbox = [manager.moduleRegistry moduleForName:"RedBox"];
[redbox updateErrorMessage:message withStack:stack errorCookie:(int)exceptionId];
if (manager.delegate && [manager.delegate respondsToSelector:@selector(updateJSExceptionWithMessage:stack:exceptionId:)]) {
[manager.delegate updateJSExceptionWithMessage:message stack:stack exceptionId:[NSNumber numberWithDouble:exceptionId]];
}
});
});
}
#pragma clang diagnostic pop
@end |
Description
In 0.65 on iOS, RedBox is displayed as well as LogBox when using console.error or throwing an Error.
React Native version:
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
npx react-native init Test --version 0.65.1
App.js
and add the following to App component:yarn start
andyarn ios
Expected Results
I expect to only see the error in LogBox at the bottom of the screen as in 0.64.2:

Actual Results
I get the Error in Redbox as well (Note that this is only an issue on iOS):
This also happens when throwing an Error, however it isn't as much of an issue as LogBox is displayed in full screen in this case anyway.
The text was updated successfully, but these errors were encountered: