-
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
Block Editor: Improve getBlockInsertionPoint
memoization
#47489
Conversation
Size Change: +35 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
state.insertionPoint?.rootClientId, | ||
state.insertionPoint?.index, | ||
state.insertionPoint?.__unstableWithInserter, | ||
state.insertionPoint?.operation, |
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 why we need to do this, these are all the keys of the state no?
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.
Because theoretically, insertionPoint
is an object, and by listing those here, we'll prevent recalculation if state.insertionPoint
is assigned a new object with the same subfields.
I don't have proof that this is causing an issue right now, the main motivation for this PR was selectionEnd
causing the issue I described. So if you prefer omitting those, I'm fine with that. Then can re-add them if we find a practical need for that.
WDYT?
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.
Yes, let's do that. Restore the insertion point and keep the change for selectionEnd. Thanks Marin
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.
Done in ab5ea8a
Thanks for the thorough and in-depth reviews, @youknowriad ❤️
Flaky tests detected in ed18db3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4023605083
|
What?
This PR improves the memoization of
getBlockInsertionPoint()
by making the list of dependents more specific. This allows us to avoid unnecessary extra rerenders when the insertion point is the same but an update is triggered just because we return a new object with the same data.Why?
After landing #47448 I noticed that there are still unnecessary re-renders caused by
getBlockInsertionPoint()
, in cases where we're moving inside the same block, for example.How?
We're listing the dependents specifically and that way we avoid unnecessary updates when new nested objects with the same data are being dispatched. This was particularly a problem for
state.selection.selectionEnd
, which can be a different object but thestate.selection.selectionEnd.clientId
will still be the same, and that's all the selector needs from that state subtree, so the update was unnecessary.Testing Instructions
Testing Instructions for Keyboard
None.
Screenshots or screencast
None.