-
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 some _.get()
from editor
#48104
Conversation
Size Change: +2.18 kB (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
Flaky tests detected in 0732876. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4185869407
|
|
||
// Only render fields if post type supports page attributes or available templates exist. | ||
if ( ! supportsPageAttributes ) { | ||
if ( ! postType?.supports?.[ 'page-attributes' ] ) { |
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.
getPostType()
could return undefined
.
), | ||
isPostTypeViewable: get( postType, [ 'viewable' ], false ), | ||
hasPublishAction: getCurrentPost()._links?.[ 'wp:action-publish' ], | ||
isPostTypeViewable: postType?.viewable, |
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.
getPostType()
could return undefined
.
@@ -21,11 +16,7 @@ export default function PostAuthorCheck( { children } ) { | |||
const post = select( editorStore ).getCurrentPost(); | |||
const authors = select( coreStore ).getUsers( AUTHORS_QUERY ); | |||
return { | |||
hasAssignAuthorAction: get( |
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.
getCurrentPost()
will always be an object:
return EMPTY_OBJECT; |
[ '_links', 'wp:action-publish' ], | ||
false | ||
), | ||
hasPublishAction: getCurrentPost()._links?.[ 'wp:action-publish' ], |
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.
getCurrentPost()
will always be an object:
return EMPTY_OBJECT; |
[ '_links', 'wp:action-publish' ], | ||
false | ||
), | ||
hasPublishAction: getCurrentPost()._links?.[ 'wp:action-publish' ], |
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.
getCurrentPost()
will always be an object:
return EMPTY_OBJECT; |
], | ||
false | ||
) | ||
? post._links?.[ 'wp:action-assign-' + _taxonomy.rest_base ] |
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.
getCurrentPost()
will always be an object:
return EMPTY_OBJECT; |
[ 'labels', 'singular_name' ], | ||
slug === 'category' ? __( 'Category' ) : __( 'Term' ) | ||
) | ||
taxonomy?.labels?.singular_name ?? defaultName |
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.
taxonomy
could be undefined.
[ 'labels', labelProperty ], | ||
slug === 'category' ? fallbackIsCategory : fallbackIsNotCategory | ||
); | ||
taxonomy?.labels?.[ labelProperty ] ?? |
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.
taxonomy
could be undefined.
__( 'Search Terms' ) | ||
); | ||
const groupLabel = get( taxonomy, [ 'name' ], __( 'Terms' ) ); | ||
const filterLabel = taxonomy?.labels?.search_items ?? __( 'Search Terms' ); |
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.
taxonomy
could be undefined.
); | ||
const groupLabel = get( taxonomy, [ 'name' ], __( 'Terms' ) ); | ||
const filterLabel = taxonomy?.labels?.search_items ?? __( 'Search Terms' ); | ||
const groupLabel = taxonomy?.name ?? __( 'Terms' ); |
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.
taxonomy
could be undefined.
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!
The changes here are straightforward, and I couldn't spot any regressions.
What?
This PR removes Lodash's
_.get()
from a bunch of@wordpress/editor
components. Most of the usages affected here are similar and that makes it easier to review as a group.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 direct access with optional chaining and nullish coalescing as an alternative.
Testing Instructions