Skip to content

Commit 71e5fa4

Browse files
committed
Wrap warnings to associate the cause
1 parent d803508 commit 71e5fa4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('ReactSuspense', () => {
5959
ReactNoop.render(elementBadType);
6060
await expect(async () => await waitForAll([])).toErrorDev([
6161
'Unexpected type for suspenseCallback.',
62+
{withoutStack: true},
6263
]);
6364

6465
const elementMissingCallback = (

0 commit comments

Comments
 (0)