Skip to content
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

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,11 @@ export const getBlockInsertionPoint = createSelector(
return { rootClientId, index };
},
( state ) => [
state.insertionPoint,
state.selection.selectionEnd,
state.insertionPoint?.rootClientId,
state.insertionPoint?.index,
state.insertionPoint?.__unstableWithInserter,
state.insertionPoint?.operation,
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Member Author

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 ❤️

state.selection.selectionEnd.clientId,
state.blocks.parents,
state.blocks.order,
]
Expand Down