Skip to content

Commit

Permalink
Force syncing on initial selection
Browse files Browse the repository at this point in the history
  • Loading branch information
stacimc committed Dec 20, 2021
1 parent 9ff244d commit a8a28c9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,10 @@ export default function LogoEdit( {
};
}, [] );

const setLogo = ( newValue ) => {
if ( shouldSyncIcon ) {
const setLogo = ( newValue, shouldForceSync = false ) => {
// `shouldForceSync` is used to force syncing when the attribute
// may not have updated yet.
if ( shouldSyncIcon || shouldForceSync ) {
setIcon( newValue );
}

Expand All @@ -465,12 +467,19 @@ export default function LogoEdit( {
// Initialize the syncSiteIcon toggle. If we currently have no Site logo and no
// site icon, automatically sync the logo to the icon.
if ( shouldSyncIcon === undefined ) {
setAttributes( { shouldSyncIcon: ! siteIconId } );
const shouldForceSync = ! siteIconId;
setAttributes( { shouldSyncIcon: shouldForceSync } );

// Because we cannot rely on the `shouldSyncIcon` attribute to have updated by
// the time `setLogo` is called, pass an argument to force the syncing.
onSelectLogo( media, shouldForceSync );
return;
}

onSelectLogo( media );
};

const onSelectLogo = ( media ) => {
const onSelectLogo = ( media, shouldForceSync = false ) => {
if ( ! media ) {
return;
}
Expand All @@ -482,7 +491,7 @@ export default function LogoEdit( {
return;
}

setLogo( media.id );
setLogo( media.id, shouldForceSync );
};

const onRemoveLogo = () => {
Expand Down

0 comments on commit a8a28c9

Please sign in to comment.