Skip to content

Commit e356fd0

Browse files
motiz88kastopia
andauthored
[0.83] Backport initial implementation of RedBox 2.0 for iOS (facebook#56574)
* Add per-platform redBoxV2 feature flags Cherry-pick of d6ed561 with feature flag files regenerated for the 0.83-stable branch. * Extract RCTRedBoxController from RCTRedBox.mm (facebook#56509) Summary: Pull Request resolved: facebook#56509 Moves the `RCTRedBoxController` class, previously inlined in `RCTRedBox.mm`, into its own implementation and header files (`RCTRedBoxController.mm`, `RCTRedBoxController+Internal.h`). An upcoming diff will fork these files for the experimental RedBox 2.0. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D101484586 fbshipit-source-id: 0b0c80caa790ee5286c48adfce5c22d22bef47b6 * Add LogBox-styled error overlay (facebook#56550) Summary: Pull Request resolved: facebook#56550 Replace the legacy red-on-black RedBox design with a LogBox-inspired design for RedBox 2.0: charcoal background, salmon header bar, structured call stack, 3-button footer, full-screen view with no animated transition. Gated behind `redBoxV2IOS`. This diff is just for the low-hanging fruit - setting up the split implementation and borrowing the broad visual style of LogBox. Further up this stack we will port more functionality and improve on this baseline. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D98115368 fbshipit-source-id: 7c14137c94c812f42b6af0c376762e068cfcdaaa * Add shared C++ error parser and ANSI renderer (facebook#56553) Summary: Pull Request resolved: facebook#56553 Add a platform-independent C++ library (`ReactCommon/react/debug/redbox/`) for error message parsing and ANSI escape sequence rendering, shared by both iOS and Android. `RedBoxErrorParser` — C++ port of `parseLogBoxException`. Classifies Metro errors, Babel transform errors, bundle loading errors, and code frame errors into a structured `ParsedError`. `AnsiParser` — converts ANSI SGR sequences into styled spans with foreground/background colors using the Afterglow theme. Uses `facebook::react::unstable_redbox` namespace to exclude from C++ API snapshots. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D101357709 fbshipit-source-id: d2ecf9d12897e00f9590e1bec57ecf5d5895fcd5 * Show syntax-highlighted code frames (facebook#56551) Summary: Pull Request resolved: facebook#56551 TSIA Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D98113191 fbshipit-source-id: 00b640de69a5a3e48dae624dd24c25a1da3c7548 * Mark all errors as retryable (facebook#56552) Summary: Pull Request resolved: facebook#56552 Adds `isRetryable` and `isCompileError` to C++ `ParsedError` and its iOS wrapper, for use in RedBox 2.0. **Currently all errors are assumed to be retryable under RedBox 2.0.** Changelog: [Internal] Reviewed By: robhogan Differential Revision: D101357708 fbshipit-source-id: 6a83b5944e5451a7818c66a321bf8d45a1951970 * Auto-reload on retryable errors (facebook#56549) Summary: Pull Request resolved: facebook#56549 Adds an automatic reload countdown to the RedBox 2.0 overlay for errors marked as retryable by the error parser. (Currently all of them, see D101357708.) Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D98107027 fbshipit-source-id: 9f39491e4ecf5086a76b7f6446c34231a5d4eb0d * Attempt to clear RedBox by automatically reloading on Metro file change (facebook#56554) Summary: Pull Request resolved: facebook#56554 While RedBox is displayed, open a native WebSocket to Metro's `/hot` endpoint. On file change, automatically reload — bridging the gap for bundle loading errors where the JS HMR client is unavailable. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D98350597 fbshipit-source-id: 9d11d99226483d937be45d75be008b0f9f25572b * Fix truncated filenames in call stack frames (facebook#56565) Summary: Pull Request resolved: facebook#56565 Stack frame file paths in RedBox 2.0 were displaying as truncated jsc-safe-url fragments (e.g. `dev=true` instead of `index.bundle`). This happened because `lastPathComponent` treats the `//&` path-encoded query as additional path segments. Here, we port the `jsc-safe-url` npm package to shared C++ (matching the JS implementation line-for-line, including the RFC 3986 appendix B regex) and use it to normalize stack frame URLs before extracting filenames. Query strings are also stripped after normalization. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D101796395 fbshipit-source-id: 38d5a8ccb111e78f847be4a551e359dd075e6a0f * Guard tvOS-unavailable APIs in RCTRedBox2Controller (facebook#56568) Summary: Pull Request resolved: facebook#56568 `separatorStyle` and `UITableViewCellSeparatorStyleNone` are unavailable on tvOS, causing the airwave-tvos-appletvos build to fail. Wrap them with `#if !TARGET_OS_TV`, matching the existing pattern in `RCTRedBoxController.mm`. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D102001404 fbshipit-source-id: 383e1cc64070000c258b71a60aa4b4ef6453206e * Fix C++ syntax in Objective-C header breaking React module build (facebook#56569) Summary: Pull Request resolved: facebook#56569 `RCTRedBox2Controller+Internal.h` used a C++ `using` type alias, which fails when compiled as plain Objective-C. This header is currently included in the `React-Core` umbrella header (via the `CoreModulesHeaders` subspec), so it gets compiled in a pure-ObjC context and breaks the RNTester iOS CI build. Here, we replace the `using` with an equivalent `typedef`. NOTE: The underlying issue is that this `+Internal.h` header should not be in the umbrella header at all. I will follow up to make the RedBox 2.0 internal headers private at the CocoaPods level. Changelog: [Internal] ___ overriding_review_checks_triggers_an_audit_and_retroactive_review Oncall Short Name: react_native landed-with-radar-review Reviewed By: sbuggay Differential Revision: D102005814 fbshipit-source-id: d0a5727ee47ea5148a371074bc74e42e503c20f8 --------- Co-authored-by: Terry Kwon <kastopia@meta.com>
1 parent 707b614 commit e356fd0

47 files changed

Lines changed: 2989 additions & 493 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/react-native/Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ let reactRendererConsistency = RNTarget(
9494
let reactDebug = RNTarget(
9595
name: .reactDebug,
9696
path: "ReactCommon/react/debug",
97+
excludedPaths: ["tests", "redbox/tests"],
9798
dependencies: [.reactNativeDependencies]
9899
)
99100
/// React-jsi.podspec
@@ -380,7 +381,7 @@ let reactCoreModules = RNTarget(
380381
name: .reactCoreModules,
381382
path: "React/CoreModules",
382383
excludedPaths: ["PlatformStubs/RCTStatusBarManager.mm"],
383-
dependencies: [.reactNativeDependencies, .jsi, .yoga, .reactTurboModuleCore]
384+
dependencies: [.reactNativeDependencies, .jsi, .yoga, .reactTurboModuleCore, .reactFeatureFlags]
384385
)
385386

386387
/// React-runtimeCore.podspec
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <Foundation/Foundation.h>
9+
10+
/**
11+
* Converts between standard URLs and JSC-safe URLs.
12+
*
13+
* JSC (JavaScriptCore) strips query strings from source URLs in stack traces
14+
* as of iOS 16.4. Metro works around this by encoding the query string into
15+
* the URL path. These methods convert between the two formats.
16+
*/
17+
@interface RCTJscSafeUrl : NSObject
18+
19+
+ (nonnull NSString *)normalUrlFromJscSafeUrl:(nonnull NSString *)url;
20+
+ (nonnull NSString *)jscSafeUrlFromNormalUrl:(nonnull NSString *)url;
21+
+ (BOOL)isJscSafeUrl:(nonnull NSString *)url;
22+
23+
@end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTJscSafeUrl+Internal.h"
9+
10+
#import <React/RCTDefines.h>
11+
#import <react/debug/redbox/JscSafeUrl.h>
12+
13+
#if RCT_DEV_MENU
14+
15+
using facebook::react::unstable_redbox::isJscSafeUrl;
16+
using facebook::react::unstable_redbox::toJscSafeUrl;
17+
using facebook::react::unstable_redbox::toNormalUrl;
18+
19+
@implementation RCTJscSafeUrl
20+
21+
+ (NSString *)normalUrlFromJscSafeUrl:(NSString *)url
22+
{
23+
return [NSString stringWithUTF8String:toNormalUrl(url.UTF8String).c_str()];
24+
}
25+
26+
+ (NSString *)jscSafeUrlFromNormalUrl:(NSString *)url
27+
{
28+
return [NSString stringWithUTF8String:toJscSafeUrl(url.UTF8String).c_str()];
29+
}
30+
31+
+ (BOOL)isJscSafeUrl:(NSString *)url
32+
{
33+
return isJscSafeUrl(url.UTF8String);
34+
}
35+
36+
@end
37+
38+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTDefines.h>
9+
#import <UIKit/UIKit.h>
10+
11+
#if RCT_DEV_MENU
12+
13+
@class RCTJSStackFrame;
14+
15+
@protocol RCTRedBoxControllerActionDelegate <NSObject>
16+
17+
- (void)redBoxController:(UIViewController *)redBoxController openStackFrameInEditor:(RCTJSStackFrame *)stackFrame;
18+
- (void)reloadFromRedBoxController:(UIViewController *)redBoxController;
19+
- (void)loadExtraDataViewController;
20+
21+
@end
22+
23+
@protocol RCTRedBoxControlling <NSObject>
24+
25+
@property (nonatomic, weak) id<RCTRedBoxControllerActionDelegate> actionDelegate;
26+
27+
- (void)showErrorMessage:(NSString *)message
28+
withStack:(NSArray<RCTJSStackFrame *> *)stack
29+
isUpdate:(BOOL)isUpdate
30+
errorCookie:(int)errorCookie;
31+
32+
- (void)dismiss;
33+
34+
@end
35+
36+
@protocol RCTRedBox2Controlling <RCTRedBoxControlling>
37+
38+
@property (nonatomic, strong, nullable) NSURL *bundleURL;
39+
40+
@end
41+
42+
#endif

0 commit comments

Comments
 (0)