diff --git a/packages/react-reconciler/src/ReactFiberCommitEffects.js b/packages/react-reconciler/src/ReactFiberCommitEffects.js index 85eb38ed30522..d69d87688a201 100644 --- a/packages/react-reconciler/src/ReactFiberCommitEffects.js +++ b/packages/react-reconciler/src/ReactFiberCommitEffects.js @@ -184,12 +184,14 @@ 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', - hookName, - addendum, - ); + runWithFiberInDEV(finishedWork, () => { + console.error( + '%s must not return anything besides a function, ' + + 'which is used for clean-up.%s', + hookName, + addendum, + ); + }); } } } @@ -642,11 +644,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(