-
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 from @wordpress/keycodes
package
#47737
Conversation
Size Change: +41 B (0%) Total Size: 1.31 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.
Thank you, @tyxla!
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.
Thank you, @tyxla! 🙌 This LGTM 🙂
Flaky tests detected in b4cd36b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4084686576
|
@Mamaduka, it would be great to include in WP 6.2 🙌🏻 |
* Lodash: Refactor away from _.get() in @wordpress/keycodes * Lodash: Refactor away from _.mapValues() in @wordpress/keycodes * Lodash: Remove dependency from @wordpress/keycodes
Cherry-picked this PR to the wp/6.2 branch. |
What?
This PR removes all of the Lodash from the
@wordpress/keycodes
package. 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 #39495A motivation to remove Lodash from the
@wordpress/keycodes
package is that it's the last one that needslodash
and is a dependency of the widely used@wordpress/compose
package.How?
The PR looks large, but that's mostly whitespace changes, due to the TS changes required for the custom
mapValues()
implementation. I recommend ignoring whitespace changes while reviewing.We have to deal with essentially a couple of methods, and migration away from them is pretty straightforward:
get
Replacing
get
is as simple as using direct access, and optional chaining with nullish coalescing.mapValues
Straightforward to replace it with a custom implementation that uses
Object.fromEntries( Object.entries().map() )
. Needs a bit of type massaging as well.Finally, we're removing the
lodash
dependency from the package completely.Testing Instructions
Code is covered by tests - verify all tests pass and all checks are green.