Skip to content

Commit

Permalink
Wrap warnings to associate the cause
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Sep 5, 2024
1 parent d803508 commit 2e92dc5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
25 changes: 17 additions & 8 deletions packages/react-reconciler/src/ReactFiberCommitEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -642,11 +649,13 @@ export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
((didWarnAboutUndefinedSnapshotBeforeUpdate: any): Set<mixed>);
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ describe('ReactSuspense', () => {
);

ReactNoop.render(elementBadType);
await expect(async () => await waitForAll([])).toErrorDev([
'Unexpected type for suspenseCallback.',
]);
await expect(async () => await waitForAll([])).toErrorDev(
['Unexpected type for suspenseCallback.'],
{withoutStack: true},
);

const elementMissingCallback = (
<React.Suspense fallback={'Waiting'}>
Expand Down

0 comments on commit 2e92dc5

Please sign in to comment.