diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/index.js b/packages/edit-site/src/components/global-styles/screen-revisions/index.js index b980d199e7be30..a50b8f13d55cc2 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/index.js +++ b/packages/edit-site/src/components/global-styles/screen-revisions/index.js @@ -3,7 +3,6 @@ */ import { __, sprintf } from '@wordpress/i18n'; import { - useNavigator, __experimentalConfirmDialog as ConfirmDialog, Spinner, } from '@wordpress/components'; @@ -33,7 +32,6 @@ const { GlobalStylesContext, areGlobalStyleConfigsEqual } = unlock( const PAGE_SIZE = 10; function ScreenRevisions() { - const { goTo } = useNavigator(); const { user: currentEditorGlobalStyles, setUserConfig } = useContext( GlobalStylesContext ); const { blocks, editorCanvasContainerView } = useSelect( @@ -71,6 +69,8 @@ function ScreenRevisions() { currentEditorGlobalStyles ); + // The actual code that triggers the revisions screen to navigate back + // to the home screen in in `packages/edit-site/src/components/global-styles/ui.js`. const onCloseRevisions = () => { const canvasContainerView = editorCanvasContainerView === 'global-styles-revisions:style-book' @@ -85,15 +85,6 @@ function ScreenRevisions() { onCloseRevisions(); }; - useEffect( () => { - if ( - ! editorCanvasContainerView || - ! editorCanvasContainerView.startsWith( 'global-styles-revisions' ) - ) { - goTo( '/' ); // Return to global styles main panel. - } - }, [ editorCanvasContainerView ] ); - useEffect( () => { if ( ! isLoading && revisions.length ) { setCurrentRevisions( revisions ); diff --git a/packages/edit-site/src/components/global-styles/ui.js b/packages/edit-site/src/components/global-styles/ui.js index fbc3e461e6abb6..198765bcaeb311 100644 --- a/packages/edit-site/src/components/global-styles/ui.js +++ b/packages/edit-site/src/components/global-styles/ui.js @@ -253,7 +253,9 @@ function GlobalStylesEditorCanvasContainerLink() { switch ( editorCanvasContainerView ) { case 'global-styles-revisions': case 'global-styles-revisions:style-book': - goTo( '/revisions' ); + if ( ! isRevisionsOpen ) { + goTo( '/revisions' ); + } break; case 'global-styles-css': goTo( '/css' ); @@ -267,7 +269,14 @@ function GlobalStylesEditorCanvasContainerLink() { * browsing global styles panel. */ if ( isRevisionsOpen ) { - goTo( '/' ); + goTo( '/', { isBack: true } ); + } + break; + default: + // In general, if the revision screen is in view but the + // `editorCanvasContainerView` is not a revision view, close it. + if ( isRevisionsOpen ) { + goTo( '/', { isBack: true } ); } break; }