diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 55db84b93fcde1..008f81be9fdf57 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -285,7 +285,8 @@ export const ExperimentalEditorProvider = withRegistryProvider( setEditedPost, setRenderingMode, } = unlock( useDispatch( editorStore ) ); - const { createWarningNotice } = useDispatch( noticesStore ); + const { createWarningNotice, removeNotice } = + useDispatch( noticesStore ); // Ideally this should be synced on each change and not just something you do once. useLayoutEffect( () => { @@ -321,7 +322,9 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Synchronizes the active post with the state useEffect( () => { setEditedPost( post.type, post.id ); - }, [ post.type, post.id, setEditedPost ] ); + // Clear any notices dependent on the post context. + removeNotice( 'template-activate-notice' ); + }, [ post.type, post.id, setEditedPost, removeNotice ] ); // Synchronize the editor settings as they change. useEffect( () => { diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index 36c0920c8f01ab..c9687c7ce96510 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -347,17 +347,12 @@ async function templateActivationNotice( { select, registry } ) { { label: __( 'Activate' ), onClick: async () => { - await registry - .dispatch( noticesStore ) - .removeNotice( 'template-activate-notice' ); await registry .dispatch( noticesStore ) .createNotice( 'info', __( 'Activating template…' ), - { - id: 'template-activating-notice', - } + { id: 'template-activate-notice' } ); try { const currentSite = await registry @@ -376,22 +371,18 @@ async function templateActivationNotice( { select, registry } ) { }, { throwOnError: true } ); - await registry - .dispatch( noticesStore ) - .removeNotice( 'template-activating-notice' ); await registry .dispatch( noticesStore ) .createSuccessNotice( - __( 'Template activated.' ) + __( 'Template activated.' ), + { id: 'template-activate-notice' } ); } catch ( error ) { - await registry - .dispatch( noticesStore ) - .removeNotice( 'template-activating-notice' ); await registry .dispatch( noticesStore ) .createErrorNotice( - __( 'Template activation failed.' ) + __( 'Template activation failed.' ), + { id: 'template-activate-notice' } ); // Rethrow for debugging. throw error;