-
Notifications
You must be signed in to change notification settings - Fork 47k
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
pure #13748
pure #13748
Conversation
A higher-order component version of the `React.PureComponent` class. During an update, the previous props are compared to the new props. If they are the same, React will skip rendering the component and its children. Unlike userspace implementations, `pure` will not add an additional fiber to the tree. The first argument must be a functional component; it does not work with classes. `pure` uses shallow comparison by default, like `React.PureComponent`. A custom comparison can be passed as the second argument. Co-authored-by: Andrew Clark <[email protected]> Co-authored-by: Sophie Alpert <[email protected]>
React: size: 🔺+0.9%, gzip: 🔺+0.8% ReactDOM: size: 🔺+0.6%, gzip: 🔺+0.7% Details of bundled changes.Comparing: 4d17c3f...645a8ba react
react-dom
react-art
react-test-renderer
react-reconciler
react-native-renderer
scheduler
Generated by 🚫 dangerJS |
workInProgress.childExpirationTime = current.childExpirationTime; | ||
if (pendingProps !== current.pendingProps) { |
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.
What's the significance of this change?
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.
Previously the expirationTime
field represented the pending priority of props, state, and context. In the begin phase, we check if this is lower priority than the render priority. If so, we can bail out.
After this change, it represents only the pending priority of state and context. The props check is moved to the begin phase. That way, in the begin phase, we can distinguish between an update caused by props versus an update caused by state or context. pure
will never bail out if state or context has changed.
@@ -124,7 +127,7 @@ export function reconcileChildren( | |||
current: Fiber | null, | |||
workInProgress: Fiber, | |||
nextChildren: any, | |||
renderExpirationTime: ExpirationTime, |
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.
Why is this here? Did prettier change?
if (isLegacyContextProvider(Component)) { | ||
pushLegacyContextProvider(workInProgress); | ||
|
||
if (current !== 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.
I don't understand the significance of these changes either.
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.
Corresponds to the changes in https://github.com/facebook/react/pull/13748/files#r221093037
} else { | ||
const prototype = render.prototype; | ||
if (!!(prototype && prototype.isReactComponent)) { | ||
warningWithoutStack( |
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.
Unit tests for the warnings pls?
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.
sorry I could have also done this
); | ||
} | ||
case PureComponentLazy: { |
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.
this duplication kills me a little bit :)
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.
Me too :D
5d22fe4
to
645a8ba
Compare
you missed a golden opportunity to call this |
It seems to be the first time React includes HOC in its public API. Do we need to expect some sort of new guides on when and how to use it? |
Agree with @alexbaumgertner , but IMO they will do that but just seems don't have much time currently, so before the release there will be blog post |
@acdlite Will DevTools need to be updated to recognize the new |
@alexeyraspopov We always include guides/docs/etc with releases. This is not a release yet. |
@acdlite Follow up facebook/react-devtools#1173 |
Maybe I'm misremembering, but wasn't one of the design goals of SFC to be pure by default? |
The goal was to make components easier to optimize. There are many ways to optimize, memoization based on shallow equality is just one possible optimization you can make. Functions already have less overhead since 16 (less property checks and memory usage), and they're also much more optimizable by compilers. Unfortunately our compilation experiments are still very early. |
Thanks for the explainer @gaearon 😄 |
* pure A higher-order component version of the `React.PureComponent` class. During an update, the previous props are compared to the new props. If they are the same, React will skip rendering the component and its children. Unlike userspace implementations, `pure` will not add an additional fiber to the tree. The first argument must be a functional component; it does not work with classes. `pure` uses shallow comparison by default, like `React.PureComponent`. A custom comparison can be passed as the second argument. Co-authored-by: Andrew Clark <[email protected]> Co-authored-by: Sophie Alpert <[email protected]> * Warn if first argument is not a functional component
* pure A higher-order component version of the `React.PureComponent` class. During an update, the previous props are compared to the new props. If they are the same, React will skip rendering the component and its children. Unlike userspace implementations, `pure` will not add an additional fiber to the tree. The first argument must be a functional component; it does not work with classes. `pure` uses shallow comparison by default, like `React.PureComponent`. A custom comparison can be passed as the second argument. Co-authored-by: Andrew Clark <[email protected]> Co-authored-by: Sophie Alpert <[email protected]> * Warn if first argument is not a functional component
* pure A higher-order component version of the `React.PureComponent` class. During an update, the previous props are compared to the new props. If they are the same, React will skip rendering the component and its children. Unlike userspace implementations, `pure` will not add an additional fiber to the tree. The first argument must be a functional component; it does not work with classes. `pure` uses shallow comparison by default, like `React.PureComponent`. A custom comparison can be passed as the second argument. Co-authored-by: Andrew Clark <[email protected]> Co-authored-by: Sophie Alpert <[email protected]> * Warn if first argument is not a functional component
Note: the discussion for this proposal is in reactjs/rfcs#63. It has since been renamed to
React.memo()
.A higher-order component version of the
React.PureComponent
class. During an update, the previous props are compared to the new props. If they are the same, React will skip rendering the component and its children.Unlike userspace implementations,
pure
will not add an additional fiber to the tree.The first argument must be a functional component; it does not work with classes.
pure
uses shallow comparison by default, likeReact.PureComponent
. A custom comparison can be passed as the second argument.