From b68449088eee717d459614c0c1f256fff377496c Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Fri, 14 May 2021 07:45:25 -0500 Subject: [PATCH] Don't filter values from arrays (#31780) --- packages/block-editor/src/hooks/utils.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/hooks/utils.js b/packages/block-editor/src/hooks/utils.js index dba018f2cfc8a..443a68bc3f596 100644 --- a/packages/block-editor/src/hooks/utils.js +++ b/packages/block-editor/src/hooks/utils.js @@ -1,23 +1,21 @@ /** * External dependencies */ -import { pickBy, isEqual, isObject, identity, mapValues } from 'lodash'; +import { pickBy, isEmpty, isObject, identity, mapValues } from 'lodash'; /** - * Removed undefined values from nested object. + * Removed falsy values from nested object. * * @param {*} object - * @return {*} Object cleaned from undefined values + * @return {*} Object cleaned from falsy values */ export const cleanEmptyObject = ( object ) => { - if ( ! isObject( object ) ) { + if ( ! isObject( object ) || Array.isArray( object ) ) { return object; } const cleanedNestedObjects = pickBy( mapValues( object, cleanEmptyObject ), identity ); - return isEqual( cleanedNestedObjects, {} ) - ? undefined - : cleanedNestedObjects; + return isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects; };