-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[Docs] no-unstable-nested-components
: Warn about memoized, nested components
#3444
Conversation
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.
Adding anything to a shared config is a semver-major change, so it's unlikely to land any time soon. I'd love to land the docs updates separately tho!
Gotcha. Let's discuss the docs changes then and I'll file the semver-major separately. |
Should we just add this logic to rules of Hooks? |
5659a2e
to
f204f11
Compare
Codecov Report
@@ Coverage Diff @@
## master #3444 +/- ##
=======================================
Coverage 97.62% 97.62%
=======================================
Files 123 123
Lines 8959 8962 +3
Branches 3272 3275 +3
=======================================
+ Hits 8746 8749 +3
Misses 213 213
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@gaearon if it's hook-related then it definitely makes sense. |
|
||
React reconciliation performs element type comparison with [reference equality](https://github.com/facebook/react/blob/v16.13.1/packages/react-reconciler/src/ReactChildFiber.js#L407). The reference to the same element changes on each re-render when defining components inside the render block. This leads to complete recreation of the current node and all its children. As a result the virtual DOM has to do extra unnecessary work and [possible bugs are introduced](https://codepen.io/ariperkkio/pen/vYLodLB). | ||
React reconciliation performs element type comparison with [reference equality](https://reactjs.org/docs/reconciliation.html#elements-of-different-types). The reference to the same element changes on each re-render when defining components inside the render block. This leads to complete recreation of the current node and all its children. As a result the virtual DOM has to do extra unnecessary work and [possible bugs are introduced](https://codepen.io/ariperkkio/pen/vYLodLB). |
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.
[possible bugs are introduced](https://codepen.io/ariperkkio/pen/vYLodLB)
I'll update this demo not to include useCallback
example at some point.
If I remember right this is the line that allows memoized nested components: eslint-plugin-react/lib/rules/no-unstable-nested-components.js Lines 435 to 436 in 2575bba
This was clearly a mistake in the rule's initial design. |
c3e74d2
to
78ad0f0
Compare
no-unstable-nested-components
: Warn about memoized, nested components
The issue this rule catches is a very common beginner issue that requires understanding of the reconciler. Ideally this issue wouldn't exist but until then let's make sure you start out with a linter that catches these issues.
I adjusted the docs to no longer recommend memoizing nested component and document migration strategies.
/cc @gaearon