From df1b67ca3caa12ce2375d7b4f81c32ce951e842a Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Tue, 11 Jan 2022 11:47:02 -0800 Subject: [PATCH] Remove logic to discard unsaved changes when last Site Logo removed This effect ran on unmount and used `getGlobalBlockCount` to determine if all Site Logo blocks have been removed, then discards any unsaved changes to the Logo and Icon. This does not work correctly in the Site Editor context, and would fire erroneously when switching between template parts, breaking the ability to 'Undo'/'Redo'. --- packages/block-library/src/site-logo/edit.js | 33 +------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index 18f151a48508d9..aad0d8b8e2ca0f 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -358,7 +358,7 @@ export default function LogoEdit( { setAttributes, isSelected, } ) { - const { className: styleClass, width, shouldSyncIcon } = attributes; + const { width, shouldSyncIcon } = attributes; const [ logoUrl, setLogoUrl ] = useState(); const ref = useRef(); @@ -406,39 +406,8 @@ export default function LogoEdit( { }; }, [] ); - const { getGlobalBlockCount } = useSelect( blockEditorStore ); const { editEntityRecord } = useDispatch( coreStore ); - useEffect( () => { - // Cleanup function to discard unsaved changes to the icon and logo when - // the block is removed. - return () => { - // Do nothing if the block is being rendered in the styles preview or the - // block inserter. - if ( - styleClass?.includes( - 'block-editor-block-types-list__site-logo-example' - ) || - styleClass?.includes( - 'block-editor-block-styles__block-preview-container' - ) - ) { - return; - } - - const logoBlockCount = getGlobalBlockCount( 'core/site-logo' ); - - // Only discard unsaved changes if we are removing the last Site Logo block - // on the page. - if ( logoBlockCount === 0 ) { - editEntityRecord( 'root', 'site', undefined, { - site_logo: undefined, - site_icon: undefined, - } ); - } - }; - }, [] ); - const setLogo = ( newValue, shouldForceSync = false ) => { // `shouldForceSync` is used to force syncing when the attribute // may not have updated yet.