[Fiber]Warn when shoulcComponentUpdate returns undefined (#8243)
* [Fiber]Warn when shoulcComponentUpdate returns undefined * Remove unnecessary fallback
Toru Kobayashi committed
Nov 10, 2016 at 01:30 UTC
d0a8d8b951a5dc9996f452a6b3c069f9e43abab7
3 files changed
+13
-2
scripts/fiber/tests-failing.txt
-1
@@ -526,7 +526,6 @@ src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js
526
* should warn about `setState` on unmounted components
527
* should warn about `setState` in render
528
* should warn about `setState` in getChildContext
529
-* should warn when shouldComponentUpdate() returns undefined
529
* should pass context to children when not owner
530
* should pass context when re-rendered for static child
531
* should pass context when re-rendered for static child within a composite component
scripts/fiber/tests-passing.txt
+1
@@ -1016,6 +1016,7 @@ src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js
1016
* should silently allow `setState`, not call cb on unmounting components
1017
* should cleanup even if render() fatals
1018
* should call componentWillUnmount before unmounting
1019
+* should warn when shouldComponentUpdate() returns undefined
1020
* should warn when componentDidUnmount method is defined
1021
* should skip update when rerendering element in container
1022
* only renders once if updated in componentWillReceiveProps
src/renderers/shared/fiber/ReactFiberClassComponent.js
+12
-1
@@ -82,7 +82,18 @@ module.exports = function(scheduleUpdate : (fiber: Fiber) => void) {
82
83
const instance = workInProgress.stateNode;
84
if (typeof instance.shouldComponentUpdate === 'function') {
85
- return instance.shouldComponentUpdate(newProps, newState);
85
+ const shouldUpdate = instance.shouldComponentUpdate(newProps, newState);
86
+
87
+ if (__DEV__) {
88
+ warning(
89
+ shouldUpdate !== undefined,
90
+ '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
91
+ 'boolean value. Make sure to return true or false.',
92
+ getName(workInProgress, instance)
93
+ );
94
+ }
95
+
96
+ return shouldUpdate;
97
}
98
99
const type = workInProgress.type;