Skip to content

Commit 8017f27

Browse files
committed
Add on(Caught|Uncaught|Recoverable) opts to RN (#28836)
## Overview There's currently a bug in RN now that we no longer re-throw errors. The `showErrorDialog` function in React Native only logs the errors as soft errors, and never a fatal. RN was depending on the global handler for the fatal error handling and logging. Instead of fixing this in `ReactFiberErrorDialog`, we can implement the new root options in RN to handle caught/uncaught/recoverable in the respective functions, and delete ReactFiberErrorDialog. I'll follow up with a RN PR to implement these options and fix the error handling. DiffTrain build for commit 0347fcd.
1 parent 4cc7d27 commit 8017f27

File tree

7 files changed

+195
-102
lines changed

7 files changed

+195
-102
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9defcd56bc3cd53ac2901ed93f29218007010434
1+
0347fcd0073cf529f67a05be86a0545c3efab8e2

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<158d73c5518a6a28f53717610189a696>>
10+
* @generated SignedSource<<bd640d85592d7d9b873f1a2f979ad51a>>
1111
*/
1212

1313
"use strict";
@@ -30286,7 +30286,7 @@ to return true:wantsResponderID| |
3028630286
return root;
3028730287
}
3028830288

30289-
var ReactVersion = "19.0.0-canary-5d6d8736";
30289+
var ReactVersion = "19.0.0-canary-9cace4d2";
3029030290

3029130291
/*
3029230292
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
@@ -31464,22 +31464,40 @@ to return true:wantsResponderID| |
3146431464
defaultOnCaughtError(error, errorInfo);
3146531465
}
3146631466

31467-
function render(element, containerTag, callback, concurrentRoot) {
31467+
function render(element, containerTag, callback, concurrentRoot, options) {
3146831468
var root = roots.get(containerTag);
3146931469

3147031470
if (!root) {
31471-
// TODO (bvaughn): If we decide to keep the wrapper component,
31471+
// TODO: these defaults are for backwards compatibility.
31472+
// Once RN implements these options internally,
31473+
// we can remove the defaults and ReactFiberErrorDialog.
31474+
var onUncaughtError = nativeOnUncaughtError;
31475+
var onCaughtError = nativeOnCaughtError;
31476+
var onRecoverableError = defaultOnRecoverableError;
31477+
31478+
if (options && options.onUncaughtError !== undefined) {
31479+
onUncaughtError = options.onUncaughtError;
31480+
}
31481+
31482+
if (options && options.onCaughtError !== undefined) {
31483+
onCaughtError = options.onCaughtError;
31484+
}
31485+
31486+
if (options && options.onRecoverableError !== undefined) {
31487+
onRecoverableError = options.onRecoverableError;
31488+
} // TODO (bvaughn): If we decide to keep the wrapper component,
3147231489
// We could create a wrapper for containerTag as well to reduce special casing.
31490+
3147331491
root = createContainer(
3147431492
containerTag,
3147531493
concurrentRoot ? ConcurrentRoot : LegacyRoot,
3147631494
null,
3147731495
false,
3147831496
null,
3147931497
"",
31480-
nativeOnUncaughtError,
31481-
nativeOnCaughtError,
31482-
defaultOnRecoverableError,
31498+
onUncaughtError,
31499+
onCaughtError,
31500+
onRecoverableError,
3148331501
null
3148431502
);
3148531503
roots.set(containerTag, root);

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<0e4b40bc0587df35c50de0d0321f8af2>>
10+
* @generated SignedSource<<34dfa97c1577841a85cbb93e6d1aa9b7>>
1111
*/
1212

1313
"use strict";
@@ -10597,7 +10597,7 @@ var roots = new Map(),
1059710597
devToolsConfig$jscomp$inline_1099 = {
1059810598
findFiberByHostInstance: getInstanceFromNode,
1059910599
bundleType: 0,
10600-
version: "19.0.0-canary-8cc7c10c",
10600+
version: "19.0.0-canary-08aa6077",
1060110601
rendererPackageName: "react-native-renderer",
1060210602
rendererConfig: {
1060310603
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10640,7 +10640,7 @@ var internals$jscomp$inline_1366 = {
1064010640
scheduleRoot: null,
1064110641
setRefreshHandler: null,
1064210642
getCurrentFiber: null,
10643-
reconcilerVersion: "19.0.0-canary-8cc7c10c"
10643+
reconcilerVersion: "19.0.0-canary-08aa6077"
1064410644
};
1064510645
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1064610646
var hook$jscomp$inline_1367 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -10714,34 +10714,52 @@ exports.getPublicInstanceFromInternalInstanceHandle = function (
1071410714
exports.isChildPublicInstance = function () {
1071510715
throw Error("isChildPublicInstance() is not available in production.");
1071610716
};
10717-
exports.render = function (element, containerTag, callback, concurrentRoot) {
10717+
exports.render = function (
10718+
element,
10719+
containerTag,
10720+
callback,
10721+
concurrentRoot,
10722+
options
10723+
) {
1071810724
var root = roots.get(containerTag);
1071910725
if (!root) {
10720-
root = concurrentRoot ? 1 : 0;
10721-
concurrentRoot = new FiberRootNode(
10726+
root = nativeOnUncaughtError;
10727+
var onCaughtError = nativeOnCaughtError,
10728+
onRecoverableError = defaultOnRecoverableError;
10729+
options &&
10730+
void 0 !== options.onUncaughtError &&
10731+
(root = options.onUncaughtError);
10732+
options &&
10733+
void 0 !== options.onCaughtError &&
10734+
(onCaughtError = options.onCaughtError);
10735+
options &&
10736+
void 0 !== options.onRecoverableError &&
10737+
(onRecoverableError = options.onRecoverableError);
10738+
concurrentRoot = concurrentRoot ? 1 : 0;
10739+
options = new FiberRootNode(
1072210740
containerTag,
10723-
root,
10741+
concurrentRoot,
1072410742
!1,
1072510743
"",
10726-
nativeOnUncaughtError,
10727-
nativeOnCaughtError,
10728-
defaultOnRecoverableError,
10744+
root,
10745+
onCaughtError,
10746+
onRecoverableError,
1072910747
null
1073010748
);
10731-
root = createFiber(3, null, null, 1 === root ? 1 : 0);
10732-
concurrentRoot.current = root;
10733-
root.stateNode = concurrentRoot;
10734-
var initialCache = createCache();
10735-
initialCache.refCount++;
10736-
concurrentRoot.pooledCache = initialCache;
10737-
initialCache.refCount++;
10738-
root.memoizedState = {
10749+
concurrentRoot = createFiber(3, null, null, 1 === concurrentRoot ? 1 : 0);
10750+
options.current = concurrentRoot;
10751+
concurrentRoot.stateNode = options;
10752+
root = createCache();
10753+
root.refCount++;
10754+
options.pooledCache = root;
10755+
root.refCount++;
10756+
concurrentRoot.memoizedState = {
1073910757
element: null,
1074010758
isDehydrated: !1,
10741-
cache: initialCache
10759+
cache: root
1074210760
};
10743-
initializeUpdateQueue(root);
10744-
root = concurrentRoot;
10761+
initializeUpdateQueue(concurrentRoot);
10762+
root = options;
1074510763
roots.set(containerTag, root);
1074610764
}
1074710765
updateContainer(element, root, null, callback);

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<7546478ab9f50ee5a66b895958b26b28>>
10+
* @generated SignedSource<<d86bdae683e0b6b9649eb43c0d5548c4>>
1111
*/
1212

1313
"use strict";
@@ -11302,7 +11302,7 @@ var roots = new Map(),
1130211302
devToolsConfig$jscomp$inline_1179 = {
1130311303
findFiberByHostInstance: getInstanceFromNode,
1130411304
bundleType: 0,
11305-
version: "19.0.0-canary-cae54ba1",
11305+
version: "19.0.0-canary-42633113",
1130611306
rendererPackageName: "react-native-renderer",
1130711307
rendererConfig: {
1130811308
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11358,7 +11358,7 @@ var roots = new Map(),
1135811358
scheduleRoot: null,
1135911359
setRefreshHandler: null,
1136011360
getCurrentFiber: null,
11361-
reconcilerVersion: "19.0.0-canary-cae54ba1"
11361+
reconcilerVersion: "19.0.0-canary-42633113"
1136211362
});
1136311363
exports.createPortal = function (children, containerTag) {
1136411364
return createPortal$1(
@@ -11419,36 +11419,54 @@ exports.getPublicInstanceFromInternalInstanceHandle = function (
1141911419
exports.isChildPublicInstance = function () {
1142011420
throw Error("isChildPublicInstance() is not available in production.");
1142111421
};
11422-
exports.render = function (element, containerTag, callback, concurrentRoot) {
11422+
exports.render = function (
11423+
element,
11424+
containerTag,
11425+
callback,
11426+
concurrentRoot,
11427+
options
11428+
) {
1142311429
var root = roots.get(containerTag);
1142411430
if (!root) {
11425-
root = concurrentRoot ? 1 : 0;
11426-
concurrentRoot = new FiberRootNode(
11431+
root = nativeOnUncaughtError;
11432+
var onCaughtError = nativeOnCaughtError,
11433+
onRecoverableError = defaultOnRecoverableError;
11434+
options &&
11435+
void 0 !== options.onUncaughtError &&
11436+
(root = options.onUncaughtError);
11437+
options &&
11438+
void 0 !== options.onCaughtError &&
11439+
(onCaughtError = options.onCaughtError);
11440+
options &&
11441+
void 0 !== options.onRecoverableError &&
11442+
(onRecoverableError = options.onRecoverableError);
11443+
concurrentRoot = concurrentRoot ? 1 : 0;
11444+
options = new FiberRootNode(
1142711445
containerTag,
11428-
root,
11446+
concurrentRoot,
1142911447
!1,
1143011448
"",
11431-
nativeOnUncaughtError,
11432-
nativeOnCaughtError,
11433-
defaultOnRecoverableError,
11449+
root,
11450+
onCaughtError,
11451+
onRecoverableError,
1143411452
null
1143511453
);
11436-
root = 1 === root ? 1 : 0;
11437-
isDevToolsPresent && (root |= 2);
11438-
root = createFiber(3, null, null, root);
11439-
concurrentRoot.current = root;
11440-
root.stateNode = concurrentRoot;
11441-
var initialCache = createCache();
11442-
initialCache.refCount++;
11443-
concurrentRoot.pooledCache = initialCache;
11444-
initialCache.refCount++;
11445-
root.memoizedState = {
11454+
concurrentRoot = 1 === concurrentRoot ? 1 : 0;
11455+
isDevToolsPresent && (concurrentRoot |= 2);
11456+
concurrentRoot = createFiber(3, null, null, concurrentRoot);
11457+
options.current = concurrentRoot;
11458+
concurrentRoot.stateNode = options;
11459+
root = createCache();
11460+
root.refCount++;
11461+
options.pooledCache = root;
11462+
root.refCount++;
11463+
concurrentRoot.memoizedState = {
1144611464
element: null,
1144711465
isDehydrated: !1,
11448-
cache: initialCache
11466+
cache: root
1144911467
};
11450-
initializeUpdateQueue(root);
11451-
root = concurrentRoot;
11468+
initializeUpdateQueue(concurrentRoot);
11469+
root = options;
1145211470
roots.set(containerTag, root);
1145311471
}
1145411472
updateContainer(element, root, null, callback);

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<a8095aaaeaf72137df4e00de44458ad8>>
10+
* @generated SignedSource<<4c35df7e60d1b43bfa4dd44c80eb34bc>>
1111
*/
1212

1313
"use strict";
@@ -30739,7 +30739,7 @@ to return true:wantsResponderID| |
3073930739
return root;
3074030740
}
3074130741

30742-
var ReactVersion = "19.0.0-canary-1adfe2d5";
30742+
var ReactVersion = "19.0.0-canary-b604e595";
3074330743

3074430744
/*
3074530745
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
@@ -31911,22 +31911,40 @@ to return true:wantsResponderID| |
3191131911
defaultOnCaughtError(error, errorInfo);
3191231912
}
3191331913

31914-
function render(element, containerTag, callback) {
31914+
function render(element, containerTag, callback, options) {
3191531915
var root = roots.get(containerTag);
3191631916

3191731917
if (!root) {
31918-
// TODO (bvaughn): If we decide to keep the wrapper component,
31918+
// TODO: these defaults are for backwards compatibility.
31919+
// Once RN implements these options internally,
31920+
// we can remove the defaults and ReactFiberErrorDialog.
31921+
var onUncaughtError = nativeOnUncaughtError;
31922+
var onCaughtError = nativeOnCaughtError;
31923+
var onRecoverableError = defaultOnRecoverableError;
31924+
31925+
if (options && options.onUncaughtError !== undefined) {
31926+
onUncaughtError = options.onUncaughtError;
31927+
}
31928+
31929+
if (options && options.onCaughtError !== undefined) {
31930+
onCaughtError = options.onCaughtError;
31931+
}
31932+
31933+
if (options && options.onRecoverableError !== undefined) {
31934+
onRecoverableError = options.onRecoverableError;
31935+
} // TODO (bvaughn): If we decide to keep the wrapper component,
3191931936
// We could create a wrapper for containerTag as well to reduce special casing.
31937+
3192031938
root = createContainer(
3192131939
containerTag,
3192231940
LegacyRoot,
3192331941
null,
3192431942
false,
3192531943
null,
3192631944
"",
31927-
nativeOnUncaughtError,
31928-
nativeOnCaughtError,
31929-
defaultOnRecoverableError,
31945+
onUncaughtError,
31946+
onCaughtError,
31947+
onRecoverableError,
3193031948
null
3193131949
);
3193231950
roots.set(containerTag, root);

0 commit comments

Comments
 (0)