Skip to content

Commit 4f34cc4

Browse files
authored
[Fiber] Don't throw away the Error object retaining the owner stack (#33976)
We currently throw away the Error once we've used to the owner stack of a Fiber once. This maybe helps a bit with memory and redoing it but we really don't expect most Fibers to hit this at all. It's not very hot. If we throw away the Error, then we can't use native debugger protocols to inspect the native stack. Instead, we'd have to maintain a url to resource map indefinitely like what Chrome DevTools does to map a url to a resource. Technically it's not even technically correct since the file path might not be reversible and could in theory conflict.
1 parent 3d14fcf commit 4f34cc4

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

packages/react-devtools-shared/src/backend/fiber/DevToolsFiberComponentStack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export function getOwnerStackByFiberInDev(
199199
if (typeof owner.tag === 'number') {
200200
const fiber: Fiber = (owner: any);
201201
owner = fiber._debugOwner;
202-
let debugStack = fiber._debugStack;
202+
let debugStack: void | null | string | Error = fiber._debugStack;
203203
// If we don't actually print the stack if there is no owner of this JSX element.
204204
// In a real app it's typically not useful since the root app is always controlled
205205
// by the framework. These also tend to have noisy stacks because they're not rooted

packages/react-reconciler/src/ReactFiberComponentStack.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,17 @@ export function getOwnerStackByFiberInDev(workInProgress: Fiber): string {
177177
if (typeof owner.tag === 'number') {
178178
const fiber: Fiber = (owner: any);
179179
owner = fiber._debugOwner;
180-
let debugStack = fiber._debugStack;
180+
const debugStack = fiber._debugStack;
181181
// If we don't actually print the stack if there is no owner of this JSX element.
182182
// In a real app it's typically not useful since the root app is always controlled
183183
// by the framework. These also tend to have noisy stacks because they're not rooted
184184
// in a React render but in some imperative bootstrapping code. It could be useful
185185
// if the element was created in module scope. E.g. hoisted. We could add a a single
186186
// stack frame for context for example but it doesn't say much if that's a wrapper.
187187
if (owner && debugStack) {
188-
if (typeof debugStack !== 'string') {
189-
// Stash the formatted stack so that we can avoid redoing the filtering.
190-
fiber._debugStack = debugStack = formatOwnerStack(debugStack);
191-
}
192-
if (debugStack !== '') {
193-
info += '\n' + debugStack;
188+
const formattedStack = formatOwnerStack(debugStack);
189+
if (formattedStack !== '') {
190+
info += '\n' + formattedStack;
194191
}
195192
}
196193
} else if (owner.debugStack != null) {

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export type Fiber = {
200200

201201
_debugInfo?: ReactDebugInfo | null,
202202
_debugOwner?: ReactComponentInfo | Fiber | null,
203-
_debugStack?: string | Error | null,
203+
_debugStack?: Error | null,
204204
_debugTask?: ConsoleTask | null,
205205
_debugNeedsRemount?: boolean,
206206

0 commit comments

Comments
 (0)