From 144dba1a114f2d8b491186639aa38ece82eaef26 Mon Sep 17 00:00:00 2001 From: Benoit Girard Date: Wed, 24 Jul 2019 10:32:00 -0700 Subject: [PATCH] Fix suspenseCallback type warning, add a test (#16194) --- .../src/ReactFiberCommitWork.js | 4 +++- .../ReactSuspenseCallback-test.internal.js | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index a16ae4fe0973c..6009ca50c237a 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -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.'); + } } } } diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js index 909eb878d821e..8a6997107b47b 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.internal.js @@ -50,6 +50,30 @@ describe('ReactSuspense', () => { return {promise, resolveRef, PromiseComp}; } + it('check type', () => { + const {PromiseComp} = createThenable(); + + const elementBadType = ( + + + + ); + + ReactNoop.render(elementBadType); + expect(() => Scheduler.unstable_flushAll()).toWarnDev([ + 'Warning: Unexpected type for suspenseCallback.', + ]); + + const elementMissingCallback = ( + + + + ); + + ReactNoop.render(elementMissingCallback); + expect(() => Scheduler.unstable_flushAll()).toWarnDev([]); + }); + it('1 then 0 suspense callback', () => { const {promise, resolveRef, PromiseComp} = createThenable();