-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Performance: Assign block list refs by constant reference #3171
Conversation
@@ -65,21 +65,24 @@ class VisualEditorBlockList extends Component { | |||
this.lastClientY = clientY; | |||
} | |||
|
|||
setBlockRef( ref, uid ) { | |||
setBlockRef( ref ) { | |||
const uid = ref.props.uid; |
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.
The only thing that bothers me about this, is that it's not obvious that we need to change this if we rename/remove the uid
prop (or if React changes the element object shape)
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.
The only thing that bothers me about this, is that it's not obvious that we need to change this if we rename/remove the
uid
prop (or if React changes the element object shape)
Sure, I can see this. I imagine if we did change the uid
prop, there'd be much more impacted code than just what's referenced here. I don't love reaching into the element props, but don't necessarily see it as an unstable API.
How could this be improved? Would a comment help clarify?
I had considered removing the ref
entirely and passing the node from the block component itself when selection starts, but this isn't sufficient since the block list needs to compare the selection with all rects of blocks in the list, so it needs access to every block's DOM node.
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.
Let's add a comment. Anyway nice improvement 👍
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 how we got rid of blockRef
using findDOMNode
Creating new function reference would cascade render to VisualEditorBlock on every render
a23ad07
to
68f6cbe
Compare
Codecov Report
@@ Coverage Diff @@
## master #3171 +/- ##
=========================================
- Coverage 31.51% 31.5% -0.01%
=========================================
Files 221 221
Lines 6305 6306 +1
Branches 1120 1120
=========================================
Hits 1987 1987
- Misses 3630 3631 +1
Partials 688 688
Continue to review full report at Codecov.
|
This introduced a regression where an error is logged when removing a block, since |
Related: #3170
This pull request seeks to optimize to eliminate a render cascade which occurs to every block when the VisualEditorBlockList component renders. Previously, we would assign a new function as the
ref
prop to every rendered VisualEditorBlock element, thereby incurring a new render to every block rendered in the post.The changes here seek to use a single constant reference of
setBlockRef
, eliminating the customblockRef
component passed toVisualEditorBlock
in favor offindDOMNode
to access the DOM node from the component instance.Testing instructions:
Verify there are no regressions in the behavior of block multi-selection.