From 2cee795d8f10d2a58ee4649e2b6f941c8a9b5363 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 2 Jul 2024 20:56:47 +1000 Subject: [PATCH] Site Editor: patterns and templates cannot be edited from sidebar mobile view (#63002) * In mobile mode, check for canvas edit mode so the "Edit" callback redirect the browser to the block editor in edit mode * I suspect that the transition is causing intermittent crashing in Chrome in mobile viewports. Turning it off as it appears more stable in local testing. * Revert unintentional change Co-authored-by: ramonjd Co-authored-by: andrewserong Co-authored-by: youknowriad Co-authored-by: t-hamano Co-authored-by: priethor Co-authored-by: annezazu Co-authored-by: ironprogrammer Co-authored-by: ivan-ottinger Co-authored-by: mrfoxtalbot --- .../edit-site/src/components/layout/router.js | 38 +++++++++++-------- .../edit-site/src/store/private-actions.js | 10 +++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index 25ab81d9a173cc..9a2307eac9eff0 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -77,6 +77,7 @@ export default function useLayoutAreas() { const isSiteEditorLoading = useIsSiteEditorLoading(); const { params } = useLocation(); const { postType, postId, path, layout, isCustom, canvas } = params; + const hasEditCanvasMode = canvas === 'edit'; useRedirectOldPaths(); // Page list @@ -93,15 +94,14 @@ export default function useLayoutAreas() { /> ), content: , - preview: ( isListLayout || canvas === 'edit' ) && ( + preview: ( isListLayout || hasEditCanvasMode ) && ( ), - mobile: - canvas === 'edit' ? ( - - ) : ( - - ), + mobile: hasEditCanvasMode ? ( + + ) : ( + + ), }, widths: { content: isListLayout ? 380 : undefined, @@ -119,10 +119,14 @@ export default function useLayoutAreas() { ), content: , - preview: ( isListLayout || canvas === 'edit' ) && ( + preview: ( isListLayout || hasEditCanvasMode ) && ( ), - mobile: , + mobile: hasEditCanvasMode ? ( + + ) : ( + + ), }, widths: { content: isListLayout ? 380 : undefined, @@ -139,8 +143,12 @@ export default function useLayoutAreas() { areas: { sidebar: , content: , - mobile: , - preview: canvas === 'edit' && ( + mobile: hasEditCanvasMode ? ( + + ) : ( + + ), + preview: hasEditCanvasMode && ( ), }, @@ -156,7 +164,7 @@ export default function useLayoutAreas() { ), preview: , - mobile: canvas === 'edit' && ( + mobile: hasEditCanvasMode && ( ), }, @@ -175,7 +183,7 @@ export default function useLayoutAreas() { /> ), preview: , - mobile: canvas === 'edit' && ( + mobile: hasEditCanvasMode && ( ), }, @@ -188,7 +196,7 @@ export default function useLayoutAreas() { ), preview: , - mobile: canvas === 'edit' && ( + mobile: hasEditCanvasMode && ( ), }, @@ -201,7 +209,7 @@ export default function useLayoutAreas() { areas: { sidebar: , preview: , - mobile: canvas === 'edit' && ( + mobile: hasEditCanvasMode && ( ), }, diff --git a/packages/edit-site/src/store/private-actions.js b/packages/edit-site/src/store/private-actions.js index bd56e30f10d11d..37164690ed7fca 100644 --- a/packages/edit-site/src/store/private-actions.js +++ b/packages/edit-site/src/store/private-actions.js @@ -13,10 +13,10 @@ import { store as editorStore } from '@wordpress/editor'; export const setCanvasMode = ( mode ) => ( { registry, dispatch } ) => { + const isMediumOrBigger = + window.matchMedia( '(min-width: 782px)' ).matches; const switchCanvasMode = () => { registry.batch( () => { - const isMediumOrBigger = - window.matchMedia( '(min-width: 782px)' ).matches; registry.dispatch( blockEditorStore ).clearSelectedBlock(); registry.dispatch( editorStore ).setDeviceType( 'Desktop' ); registry @@ -59,7 +59,11 @@ export const setCanvasMode = } ); }; - if ( ! document.startViewTransition ) { + /* + * Skip transition in mobile, otherwise it crashes the browser. + * See: https://github.com/WordPress/gutenberg/pull/63002. + */ + if ( ! isMediumOrBigger || ! document.startViewTransition ) { switchCanvasMode(); } else { document.documentElement.classList.add(