-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lodash: Refactor post editor away from _.find()
#46432
Conversation
@@ -44,8 +39,7 @@ const enhance = compose( | |||
// Otherwise, only pass `originalBlockClientId` if it refers to a different | |||
// block from the current one. | |||
const blocks = select( blockEditorStore ).getBlocks(); | |||
const firstOfSameType = find( | |||
blocks, | |||
const firstOfSameType = blocks.find( |
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.
blocks
will always be an array:
return state.blocks.tree.get( treeKey )?.innerBlocks || EMPTY_ARRAY; |
Size Change: -19 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
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've said before, but here goes again 😄 It's so helpful that you add the links! Thanks!
What?
This PR removes Lodash's
_.find()
from theedit-post
package. There is a single usage in that package and conversion is pretty straightforward.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
We're using
Array.prototype.find()
, no additional checks are necessary since it's always invoked on an array.Testing Instructions
multiple
, so try addingmultiple
to the block metadata of any block, and verify that you can't insert it more than once without getting a warning.