From 8ca51d65a27b25d5efe8cbbb88e2ba41f43ef980 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Wed, 4 Sep 2024 19:15:47 -0400 Subject: [PATCH] Wrap warnings to associate the cause --- .../src/ReactFiberCommitEffects.js | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitEffects.js b/packages/react-reconciler/src/ReactFiberCommitEffects.js index 85eb38ed30522..1d9d5c65b8aa4 100644 --- a/packages/react-reconciler/src/ReactFiberCommitEffects.js +++ b/packages/react-reconciler/src/ReactFiberCommitEffects.js @@ -184,9 +184,16 @@ export function commitHookEffectListMount( } else { addendum = ' You returned: ' + destroy; } - console.error( - '%s must not return anything besides a function, ' + - 'which is used for clean-up.%s', + runWithFiberInDEV( + finishedWork, + (n, a) => { + console.error( + '%s must not return anything besides a function, ' + + 'which is used for clean-up.%s', + n, + a, + ); + }, hookName, addendum, ); @@ -642,11 +649,13 @@ export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) { ((didWarnAboutUndefinedSnapshotBeforeUpdate: any): Set); if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) { didWarnSet.add(finishedWork.type); - console.error( - '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + - 'must be returned. You have returned undefined.', - getComponentNameFromFiber(finishedWork), - ); + runWithFiberInDEV(finishedWork, () => { + console.error( + '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + + 'must be returned. You have returned undefined.', + getComponentNameFromFiber(finishedWork), + ); + }); } } else { snapshot = callGetSnapshotBeforeUpdates(