components/utils/font: refactor away from lodash .get#48629
Conversation
.get
|
Size Change: +3 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in d4b9bca. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4303096173
|
| */ | ||
| export function font( value ) { | ||
| return get( FONT, value, '' ); | ||
| return FONT[ value ] ?? ''; |
There was a problem hiding this comment.
Unfortunately, this won't work; value could contain dots that define a nested path, for example:
We'll need to parse and account for those when retrieving the field value. You could borrow the getValueFromObjectPath() helper from #48491 which does essentially that.
There was a problem hiding this comment.
I don't think it's a path. The keys of the FONT map contain dots, too. The JSDoc mentions its expecting one of those keys. Think we're good in this case.
There was a problem hiding this comment.
Glad this was a false alarm. Thanks for double-checking. I've confirmed that you're correct. 👍
What?
This PR removes Lodash's
_.get()from thefonthelper utility in the components package.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-fetchpackage haslodashas a dependency #39495How?
We're using nullish coalescing instead.
Testing Instructions
npm run storybook:dev) and inspect all the stories of theInputControlcomponent. Make sure it looks exactly the same as here: InputControl (Storybook).