Skip to content

Commit

Permalink
Disable owner stacks from console.error when createTask is available
Browse files Browse the repository at this point in the history
We rely on the native stack when console.createTask is available in the runtime.
  • Loading branch information
sebmarkbage committed May 23, 2024
1 parent 157af5e commit 3c4f61a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/shared/consoleWithStackDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import ReactSharedInternals from 'shared/ReactSharedInternals';
import {enableOwnerStacks} from 'shared/ReactFeatureFlags';

let suppressWarning = false;
export function setSuppressWarning(newSuppressWarning) {
Expand Down Expand Up @@ -36,14 +37,20 @@ export function error(format, ...args) {
}
}

// eslint-disable-next-line react-internal/no-production-logging
const supportsCreateTask = __DEV__ && enableOwnerStacks && !!console.createTask;

function printWarning(level, format, args) {
// When changing this logic, you might want to also
// update consoleWithStackDev.www.js as well.
if (__DEV__) {
const isErrorLogger =
format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';

if (ReactSharedInternals.getCurrentStack) {
if (!supportsCreateTask && ReactSharedInternals.getCurrentStack) {
// We only add the current stack to the console when createTask is not supported.
// Since createTask requires DevTools to be open to work, this means that stacks
// can be lost while DevTools isn't open but we can't detect this.
const stack = ReactSharedInternals.getCurrentStack();
if (stack !== '') {
format += '%s';
Expand Down

0 comments on commit 3c4f61a

Please sign in to comment.