mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix suspenseCallback type warning, add a test (#16194)
This commit is contained in:
committed by
Dominic Gannaway
parent
7ad221126f
commit
144dba1a11
+3
-1
@@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user