-
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
Lodash: Remove completely from @wordpress/create-block
package
#43362
Conversation
Size Change: 0 B Total Size: 1.24 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.
LGTM, thank you @tyxla! 👍
@@ -66,7 +61,7 @@ const dashicon = { | |||
message: | |||
'The dashicon to make it easier to identify your block (optional):', | |||
validate( input ) { | |||
if ( ! isEmpty( input ) && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) { |
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.
Why was _.isEmpty
being used on a string? So odd.
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.
This was added 3 years ago and back then using Lodash was just fine for anything 🤷 .
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 think it was about the length then you could leave it up to the regular expression that requires a starting letter. I don't remember what input
can resolve to, but I guess it might be better to check if the input
is a string.
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.
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.
Great, thank you for confirming.
What?
This PR removes all of the Lodash from the
@wordpress/create-block
package, including thelodash
dependency altogether. There are just a few usages 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 #39495While this PR doesn't affect bundle size at all (because this package's code is not bundled), it still is a step forward in the direction of completely getting rid of Lodash in Gutenberg.
How?
We're using native JS functionality -
pickBy
andomitBy
are replaced withObject.fromEntries( Object.entries().filter() )
,forEach()
for an object is also replaced byObject.entries().forEach()
, andisEmpty
is replaced with a simpler alternative due to the fact that we don't need the granularity.Testing Instructions
npx @wordpress/create-block
and go through the prompts to verify everything still works well.npx @wordpress/create-block example-block --title My Example Block
(and maybe some additional arguments) and verify everything still works well.nvm install v10.24.1
)npx @wordpress/create-block
and verify you're still getting the minimum system requirements error.