Skip to content

Commit 5adda9c

Browse files
committed
Don't append Component Stack in React DevTools if we already have a native task
If the current Fiber already has a native task, then it might be in a native async task and so we already have a component stack. If it doesn't have a native task, it's because this is not DEV mode or it's an older React or React didn't detect console.createTask.
1 parent e347e83 commit 5adda9c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ export function getStackByFiberInDevAndProd(
9898
return '\nError generating stack: ' + x.message + '\n' + x.stack;
9999
}
100100
}
101+
102+
export function supportsNativeConsoleTasks(fiber: Fiber): boolean {
103+
// If this Fiber supports native console.createTask then we are already running
104+
// inside a native async stack trace if it's active - meaning the DevTools is open.
105+
// Ideally we'd detect if this task was created while the DevTools was open or not.
106+
return !!fiber._debugTask;
107+
}

packages/react-devtools-shared/src/backend/console.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import type {
1818
import {format, formatWithStyles} from './utils';
1919

2020
import {getInternalReactConstants, getDispatcherRef} from './renderer';
21-
import {getStackByFiberInDevAndProd} from './DevToolsFiberComponentStack';
21+
import {
22+
getStackByFiberInDevAndProd,
23+
supportsNativeConsoleTasks,
24+
} from './DevToolsFiberComponentStack';
2225
import {consoleManagedByDevToolsDuringStrictMode} from 'react-devtools-feature-flags';
2326
import {castBool, castBrowserTheme} from '../utils';
2427

@@ -235,7 +238,10 @@ export function patch({
235238
}
236239
}
237240

238-
if (shouldAppendWarningStack) {
241+
if (
242+
shouldAppendWarningStack &&
243+
!supportsNativeConsoleTasks(current)
244+
) {
239245
const componentStack = getStackByFiberInDevAndProd(
240246
workTagMap,
241247
current,

0 commit comments

Comments
 (0)