-
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 _.isEmpty()
from site editor
#50917
Conversation
@@ -14,7 +9,7 @@ const { Fill: ToolsMoreMenuGroup, Slot } = createSlotFill( | |||
|
|||
ToolsMoreMenuGroup.Slot = ( { fillProps } ) => ( | |||
<Slot fillProps={ fillProps }> | |||
{ ( fills ) => ! isEmpty( fills ) && fills } | |||
{ ( fills ) => fills && fills.length > 0 } |
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.
fills
are always an array:
const fills = ( getFills( name, this ) ?? [] ) |
I can actually remove the fills &&
check, but decided to keep it just in case.
@@ -30,6 +25,10 @@ import EditorCanvasContainer from '../editor-canvas-container'; | |||
const { ExperimentalBlockEditorProvider, useGlobalStylesOutputWithConfig } = | |||
unlock( blockEditorPrivateApis ); | |||
|
|||
function isObjectEmpty( object ) { |
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.
Used 4 times, so it can't hurt to have it as an inline helper function.
@@ -42,7 +41,7 @@ function Revisions( { onClose, userConfig, blocks } ) { | |||
); | |||
|
|||
const mergedConfig = useMemo( () => { | |||
if ( ! isEmpty( userConfig ) && ! isEmpty( baseConfig ) ) { | |||
if ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) { |
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.
Both userConfig
and baseConfig
are objects, but we're adding safeguards just in case.
@@ -65,7 +64,7 @@ function Revisions( { onClose, userConfig, blocks } ) { | |||
const [ globalStyles ] = useGlobalStylesOutputWithConfig( mergedConfig ); | |||
|
|||
const editorStyles = | |||
! isEmpty( globalStyles ) && ! isEmpty( userConfig ) | |||
! isObjectEmpty( globalStyles ) && ! isObjectEmpty( userConfig ) |
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.
Both userConfig
and globalStyles
are objects, but we're adding safeguards just in case.
if ( | ||
isDirty && | ||
userConfig && | ||
Object.keys( userConfig ).length > 0 && |
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.
userConfig
is already used as a potentially nullish object, which is why we're adding the extra checks.
Size Change: +7 B (0%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
Flaky tests detected in eaeebf9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5071041040
|
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.
What?
This PR removes Lodash's
_.isEmpty()
from the site editor.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?
An object is empty if it's not an object or if it has zero properties. We're using truthiness checks and
Object.keys().length
to verify that.Testing Instructions