From 2b0bca0a1b56d5c43c814b568076d31e620ecf79 Mon Sep 17 00:00:00 2001 From: sebmarkbage Date: Fri, 23 Feb 2024 17:09:58 +0000 Subject: [PATCH] Include server component names in the componentStack in DEV (#28415) I'm a bit ambivalent about this one because it's not the main strategy that I plan on pursuing. I plan on replacing most DEV-only specific stacks like `console.error` stacks with a new take on owner stacks and native stacks. The future owner stacks may or may not be exposed to error boundaries in DEV but if they are they'd be a new errorInfo property since they're owner based and not available in prod. The use case in `console.error` mostly goes away in the future so this PR is mainly for error boundaries. It doesn't hurt to have it in there while I'm working on the better stacks though. The `componentStack` property exposed to error boundaries is more like production behavior similar to `new Error().stack` (which even in DEV won't ever expose owner stacks because `console.createTask` doesn't affect these). I'm not sure it's worth adding server components in DEV (this PR) because then you have forked behavior between dev and prod. However, since even in the future there won't be any other place to get the *parent* stack, maybe this can be useful information even if it's only dev. We could expose a third property on errorInfo that's DEV only and parent stack but including server components. That doesn't seem worth it over just having the stack differ in dev and prod. I don't plan on adding line/column number to these particular stacks. A follow up could be to add this to Fizz prerender too but only in DEV. DiffTrain build for commit https://github.com/facebook/react/commit/8fb0233a845974b4b1049e54b6c25dc54d6dd173. --- .../cjs/ReactTestRenderer-dev.js | 27 ++++++++++++++++--- .../cjs/ReactTestRenderer-prod.js | 4 +-- .../cjs/ReactTestRenderer-profiling.js | 4 +-- .../RKJSModules/vendor/react/cjs/React-dev.js | 2 +- .../vendor/react/cjs/React-prod.js | 2 +- .../vendor/react/cjs/React-profiling.js | 2 +- .../Libraries/Renderer/REVISION | 2 +- .../implementations/ReactFabric-dev.fb.js | 27 ++++++++++++++++--- .../ReactNativeRenderer-dev.fb.js | 27 ++++++++++++++++--- 9 files changed, 80 insertions(+), 17 deletions(-) diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js index 935b75109b852..d7add38913e8b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<<20ec57c573e0a0a7a0d1a3309fa44b1b>> */ "use strict"; @@ -4112,6 +4112,12 @@ if (__DEV__) { return describeComponentFrame(name, ownerName); } } + function describeDebugInfoFrame(name, env) { + return describeBuiltInComponentFrame( + name + (env ? " (" + env + ")" : ""), + null + ); + } { var PossiblyWeakMap$1 = typeof WeakMap === "function" ? WeakMap : Map; @@ -4190,7 +4196,22 @@ if (__DEV__) { var node = workInProgress; do { - info += describeFiber(node); // $FlowFixMe[incompatible-type] we bail out when we get a null + info += describeFiber(node); + + if (true) { + // Add any Server Component stack frames in reverse order. + var debugInfo = node._debugInfo; + + if (debugInfo) { + for (var i = debugInfo.length - 1; i >= 0; i--) { + var entry = debugInfo[i]; + + if (typeof entry.name === "string") { + info += describeDebugInfoFrame(entry.name, entry.env); + } + } + } + } // $FlowFixMe[incompatible-type] we bail out when we get a null node = node.return; } while (node); @@ -25707,7 +25728,7 @@ if (__DEV__) { return root; } - var ReactVersion = "18.3.0-canary-66c834640-20240223"; + var ReactVersion = "18.3.0-canary-8fb0233a8-20240223"; // Might add PROFILE later. diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js index 649c308f61766..683268c3b2184 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js @@ -9171,7 +9171,7 @@ var devToolsConfig$jscomp$inline_1014 = { throw Error("TestRenderer does not support findFiberByHostInstance()"); }, bundleType: 0, - version: "18.3.0-canary-66c834640-20240223", + version: "18.3.0-canary-8fb0233a8-20240223", rendererPackageName: "react-test-renderer" }; var internals$jscomp$inline_1195 = { @@ -9202,7 +9202,7 @@ var internals$jscomp$inline_1195 = { scheduleRoot: null, setRefreshHandler: null, getCurrentFiber: null, - reconcilerVersion: "18.3.0-canary-66c834640-20240223" + reconcilerVersion: "18.3.0-canary-8fb0233a8-20240223" }; if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) { var hook$jscomp$inline_1196 = __REACT_DEVTOOLS_GLOBAL_HOOK__; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js index 8d45e5156147c..61dc7ddb99479 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js @@ -9599,7 +9599,7 @@ var devToolsConfig$jscomp$inline_1056 = { throw Error("TestRenderer does not support findFiberByHostInstance()"); }, bundleType: 0, - version: "18.3.0-canary-66c834640-20240223", + version: "18.3.0-canary-8fb0233a8-20240223", rendererPackageName: "react-test-renderer" }; var internals$jscomp$inline_1236 = { @@ -9630,7 +9630,7 @@ var internals$jscomp$inline_1236 = { scheduleRoot: null, setRefreshHandler: null, getCurrentFiber: null, - reconcilerVersion: "18.3.0-canary-66c834640-20240223" + reconcilerVersion: "18.3.0-canary-8fb0233a8-20240223" }; if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) { var hook$jscomp$inline_1237 = __REACT_DEVTOOLS_GLOBAL_HOOK__; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js index c2f0738dcc27d..8f118752b2243 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js @@ -26,7 +26,7 @@ if (__DEV__) { } var dynamicFlags = require("ReactNativeInternalFeatureFlags"); - var ReactVersion = "18.3.0-canary-66c834640-20240223"; + var ReactVersion = "18.3.0-canary-8fb0233a8-20240223"; // ATTENTION // When adding new symbols to this file, diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js index e780b862379de..5f773c0beee7a 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js @@ -600,4 +600,4 @@ exports.useSyncExternalStore = function ( exports.useTransition = function () { return ReactCurrentDispatcher.current.useTransition(); }; -exports.version = "18.3.0-canary-66c834640-20240223"; +exports.version = "18.3.0-canary-8fb0233a8-20240223"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js index 8d4cc388387ba..4c5d386236a63 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js @@ -596,7 +596,7 @@ exports.useSyncExternalStore = function ( exports.useTransition = function () { return ReactCurrentDispatcher.current.useTransition(); }; -exports.version = "18.3.0-canary-66c834640-20240223"; +exports.version = "18.3.0-canary-8fb0233a8-20240223"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION index 64c6cf9d2de3d..7520b6c5ac63b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION @@ -1 +1 @@ -66c8346401d271588e4c400921c5dab5478fc623 +8fb0233a845974b4b1049e54b6c25dc54d6dd173 diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js index e1b0180f3afaa..6017f2c312234 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<4c526192e135ce4617cc964ef360f7e3>> + * @generated SignedSource<<0fa268fef623a046bc40195fb725492a>> */ "use strict"; @@ -7757,6 +7757,12 @@ to return true:wantsResponderID| | return describeComponentFrame(name, ownerName); } } + function describeDebugInfoFrame(name, env) { + return describeBuiltInComponentFrame( + name + (env ? " (" + env + ")" : ""), + null + ); + } var reentry = false; var componentFrameCache; @@ -8088,7 +8094,22 @@ to return true:wantsResponderID| | var node = workInProgress; do { - info += describeFiber(node); // $FlowFixMe[incompatible-type] we bail out when we get a null + info += describeFiber(node); + + if (true) { + // Add any Server Component stack frames in reverse order. + var debugInfo = node._debugInfo; + + if (debugInfo) { + for (var i = debugInfo.length - 1; i >= 0; i--) { + var entry = debugInfo[i]; + + if (typeof entry.name === "string") { + info += describeDebugInfoFrame(entry.name, entry.env); + } + } + } + } // $FlowFixMe[incompatible-type] we bail out when we get a null node = node.return; } while (node); @@ -28018,7 +28039,7 @@ to return true:wantsResponderID| | return root; } - var ReactVersion = "18.3.0-canary-0435735f"; + var ReactVersion = "18.3.0-canary-868fc9ad"; function createPortal$1( children, diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js index c1ec7b1a7fb51..24b06daac516e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<2b24b949db80030833f17449b6904d8c>> + * @generated SignedSource<<5be82410d05ff93f97b00ace398de099>> */ "use strict"; @@ -8028,6 +8028,12 @@ to return true:wantsResponderID| | return describeComponentFrame(name, ownerName); } } + function describeDebugInfoFrame(name, env) { + return describeBuiltInComponentFrame( + name + (env ? " (" + env + ")" : ""), + null + ); + } var reentry = false; var componentFrameCache; @@ -8359,7 +8365,22 @@ to return true:wantsResponderID| | var node = workInProgress; do { - info += describeFiber(node); // $FlowFixMe[incompatible-type] we bail out when we get a null + info += describeFiber(node); + + if (true) { + // Add any Server Component stack frames in reverse order. + var debugInfo = node._debugInfo; + + if (debugInfo) { + for (var i = debugInfo.length - 1; i >= 0; i--) { + var entry = debugInfo[i]; + + if (typeof entry.name === "string") { + info += describeDebugInfoFrame(entry.name, entry.env); + } + } + } + } // $FlowFixMe[incompatible-type] we bail out when we get a null node = node.return; } while (node); @@ -28458,7 +28479,7 @@ to return true:wantsResponderID| | return root; } - var ReactVersion = "18.3.0-canary-a4796866"; + var ReactVersion = "18.3.0-canary-0c89aec8"; function createPortal$1( children,