-
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 away from _.get()
in resolvers cache middleware
#47743
Conversation
Size Change: +22 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.
LGTM. Since null
and undefined
are treated the same way in the subsequent code, we don't have to worry about this difference between get()
and ?.
👍
Thanks, @tyxla!
Flaky tests detected in cf5f9a0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4085418718
|
What?
This PR removes Lodash's
_.get()
from the@wordpress/data
resolvers cache middleware module. There is just a single use in that module 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 replacing
_.get()
with a combination of direct access and optional chaining. We're using optional chaining everywhere just in case because this middleware could be used externally and our best bet is to preserve backward compatibility and guard against any missing properties along the line. That also makes the PR pretty safe to land.Testing Instructions