-
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: Remove _.pickBy()
from editor hooks
#46982
Conversation
pickBy( | ||
nextAttributes, | ||
( value, key ) => metaAttributes[ key ] | ||
Object.entries( nextAttributes ?? {} ) |
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.
nextAttributes
could theoretically be nullish, so we're falling back to an empty object just in case.
@@ -108,7 +107,11 @@ const createWithMetaAttributeSource = ( metaAttributes ) => | |||
function shimAttributeSource( settings ) { | |||
/** @type {WPMetaAttributeMapping} */ | |||
const metaAttributes = mapValues( | |||
pickBy( settings.attributes, { source: 'meta' } ), | |||
Object.fromEntries( | |||
Object.entries( settings.attributes ?? {} ).filter( |
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.
settings.attributes
could theoretically be nullish, so we're falling back to an empty object just in case.
Size Change: +17 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
Flaky tests detected in 38c60a4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3874406863
|
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.
LGTM, great work @tyxla! 👍
What?
This PR removes Lodash's
_.pickBy()
from the editor hooks. There are just a couple of usages in that block 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
Object.fromEntries( Object.entries() )
withArray.prototype.filter()
instead of_.pickBy()
.Testing Instructions
/packages/e2e-tests/plugins
directory.meta-attributes-block.php
and themeta-attributes-block
directory.my_meta
meta updates on save.my_meta
on save, the content inside the blocks changes.