Skip to content

Commit

Permalink
[Fiber]Warn when shoulcComponentUpdate returns undefined (facebook#8243)
Browse files Browse the repository at this point in the history
* [Fiber]Warn when shoulcComponentUpdate returns undefined

* Remove unnecessary fallback
  • Loading branch information
koba04 authored and gaearon committed Nov 9, 2016
1 parent 84b8bbd commit d0a8d8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js
* should warn about `setState` on unmounted components
* should warn about `setState` in render
* should warn about `setState` in getChildContext
* should warn when shouldComponentUpdate() returns undefined
* should pass context to children when not owner
* should pass context when re-rendered for static child
* should pass context when re-rendered for static child within a composite component
Expand Down
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js
* should silently allow `setState`, not call cb on unmounting components
* should cleanup even if render() fatals
* should call componentWillUnmount before unmounting
* should warn when shouldComponentUpdate() returns undefined
* should warn when componentDidUnmount method is defined
* should skip update when rerendering element in container
* only renders once if updated in componentWillReceiveProps
Expand Down
13 changes: 12 additions & 1 deletion src/renderers/shared/fiber/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ module.exports = function(scheduleUpdate : (fiber: Fiber) => void) {

const instance = workInProgress.stateNode;
if (typeof instance.shouldComponentUpdate === 'function') {
return instance.shouldComponentUpdate(newProps, newState);
const shouldUpdate = instance.shouldComponentUpdate(newProps, newState);

if (__DEV__) {
warning(
shouldUpdate !== undefined,
'%s.shouldComponentUpdate(): Returned undefined instead of a ' +
'boolean value. Make sure to return true or false.',
getName(workInProgress, instance)
);
}

return shouldUpdate;
}

const type = workInProgress.type;
Expand Down

0 comments on commit d0a8d8b

Please sign in to comment.