Skip to content
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

Site Editor: Fix broken 'Redo' by removing faulty logic for discarding unsaved Logo changes #37895

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand Down