Skip to content

Commit 2e92dc5

Browse files
committed
Wrap warnings to associate the cause
1 parent d803508 commit 2e92dc5

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

packages/react-reconciler/src/ReactFiberCommitEffects.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,16 @@ export function commitHookEffectListMount(
184184
} else {
185185
addendum = ' You returned: ' + destroy;
186186
}
187-
console.error(
188-
'%s must not return anything besides a function, ' +
189-
'which is used for clean-up.%s',
187+
runWithFiberInDEV(
188+
finishedWork,
189+
(n, a) => {
190+
console.error(
191+
'%s must not return anything besides a function, ' +
192+
'which is used for clean-up.%s',
193+
n,
194+
a,
195+
);
196+
},
190197
hookName,
191198
addendum,
192199
);
@@ -642,11 +649,13 @@ export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
642649
((didWarnAboutUndefinedSnapshotBeforeUpdate: any): Set<mixed>);
643650
if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
644651
didWarnSet.add(finishedWork.type);
645-
console.error(
646-
'%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +
647-
'must be returned. You have returned undefined.',
648-
getComponentNameFromFiber(finishedWork),
649-
);
652+
runWithFiberInDEV(finishedWork, () => {
653+
console.error(
654+
'%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +
655+
'must be returned. You have returned undefined.',
656+
getComponentNameFromFiber(finishedWork),
657+
);
658+
});
650659
}
651660
} else {
652661
snapshot = callGetSnapshotBeforeUpdates(

packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ describe('ReactSuspense', () => {
5757
);
5858

5959
ReactNoop.render(elementBadType);
60-
await expect(async () => await waitForAll([])).toErrorDev([
61-
'Unexpected type for suspenseCallback.',
62-
]);
60+
await expect(async () => await waitForAll([])).toErrorDev(
61+
['Unexpected type for suspenseCallback.'],
62+
{withoutStack: true},
63+
);
6364

6465
const elementMissingCallback = (
6566
<React.Suspense fallback={'Waiting'}>

0 commit comments

Comments
 (0)