Skip to content

Commit

Permalink
Fix suspenseCallback type warning, add a test (#16194)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgirard authored and trueadm committed Jul 24, 2019
1 parent 7ad2211 commit 144dba1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,9 @@ function commitSuspenseComponent(finishedWork: Fiber) {
suspenseCallback(new Set(thenables));
}
} else if (__DEV__) {
warning(false, 'Unexpected type for suspenseCallback.');
if (suspenseCallback !== undefined) {
warning(false, 'Unexpected type for suspenseCallback.');
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ describe('ReactSuspense', () => {
return {promise, resolveRef, PromiseComp};
}

it('check type', () => {
const {PromiseComp} = createThenable();

const elementBadType = (
<React.Suspense suspenseCallback={1} fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);

ReactNoop.render(elementBadType);
expect(() => Scheduler.unstable_flushAll()).toWarnDev([
'Warning: Unexpected type for suspenseCallback.',
]);

const elementMissingCallback = (
<React.Suspense fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);

ReactNoop.render(elementMissingCallback);
expect(() => Scheduler.unstable_flushAll()).toWarnDev([]);
});

it('1 then 0 suspense callback', () => {
const {promise, resolveRef, PromiseComp} = createThenable();

Expand Down

0 comments on commit 144dba1

Please sign in to comment.