From d032bf368525942fe4899469b1ad169e2152fb8b Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 1 Mar 2022 09:12:15 +0000 Subject: [PATCH] Avoid error when 'styles' settings are removed (#39091) * Edit Post: Avoid error when 'styles' are removed * Fix useGlobalStylesRenderer --- packages/edit-post/src/editor.js | 4 ++-- .../src/components/editor/global-styles-renderer.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index ed280e35867fee..13681a294c8940 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { size, map, without } from 'lodash'; +import { forEach, size, map, without } from 'lodash'; /** * WordPress dependencies @@ -163,7 +163,7 @@ function Editor( { const styles = useMemo( () => { const themeStyles = []; const presetStyles = []; - settings.styles.forEach( ( style ) => { + forEach( settings.styles, ( style ) => { if ( ! style.__unstableType || style.__unstableType === 'theme' ) { themeStyles.push( style ); } else { diff --git a/packages/edit-site/src/components/editor/global-styles-renderer.js b/packages/edit-site/src/components/editor/global-styles-renderer.js index f046cf7d464094..3abcb1813fd572 100644 --- a/packages/edit-site/src/components/editor/global-styles-renderer.js +++ b/packages/edit-site/src/components/editor/global-styles-renderer.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { filter } from 'lodash'; + /** * WordPress dependencies */ @@ -25,7 +30,8 @@ function useGlobalStylesRenderer() { } const currentStoreSettings = getSettings(); - const nonGlobalStyles = currentStoreSettings?.styles?.filter( + const nonGlobalStyles = filter( + currentStoreSettings.styles, ( style ) => ! style.isGlobalStyles ); updateSettings( {