-
Notifications
You must be signed in to change notification settings - Fork 49.2k
[Fiber] PureComponent #8118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fiber] PureComponent #8118
Conversation
} | ||
|
||
const type = workInProgress.type; | ||
if (type.prototype && type.prototype.isPureReactComponent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorta unfortunate if we need to check this every time. @sebmarkbage is there a place we could store this flag on the fiber?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a new TypeOfWork https://github.com/facebook/react/blob/master/src/renderers/shared/fiber/ReactTypeOfWork.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured we start off with all of these being detected on demand and then we can create optimized paths for common patterns. E.g. for things that have shouldComponentUpdate, and things that are pure components and things that have no update life-cycles etc. by storing that in the tag like @acdlite said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the element itself could already have this information in its tag so that we don't even have to detect this during mount.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, this can explode number of code paths so I figured we might want to optimize for collections of common patterns. For example: isPureComponent + no life-cycles. isPureComponent + only componentDidUpdate/componentWillUnmount but no other life-cycles. That way we can branch early and not do any of the checks. Never schedule update effects etc. EDIT: Although I guess it could also be a bitmask that allows this check to be optimized regardless of other early branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the bitmask idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's wait on the bitmap thing for now until we know the layout we want for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah I didn't mean I would add it now :D
!(updateQueue && updateQueue.isForced) && | ||
workInProgress.memoizedProps !== null && | ||
!instance.shouldComponentUpdate(newProps, newState)) { | ||
if (!checkShouldComponentUpdate(workInProgress, workInProgress.memoizedProps, newProps, newState)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line length
@@ -73,6 +74,28 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori | |||
}, | |||
}; | |||
|
|||
function checkShouldComponentUpdate(workInProgress, oldProps, newProps, newState) { | |||
if (oldProps === null || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting please:
if (
oldProps === null ||
(workInProgress.updateQueue && workInProgress.updateQueue.isForced)
) {
(Also, may as well pull updateQueue out to a var like before?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or meh, you can leave it if you like the other way. we're inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
0ea690a
to
ecbe4fa
Compare
One more lint. |
Passes existing PureComponent tests
ecbe4fa
to
59c9464
Compare
My bad, I had my ESLint plugin disabled. |
Pretty straightforward. Passes existing tests.