From 9cebb6a2979c784594e9a51f973d30f29d0d0939 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 | 30 +++++++++---------- .../edit-site/src/store/private-actions.js | 10 +++++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index 36ca52088f6a8..4637b9e1f6110 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -75,6 +75,7 @@ function useRedirectOldPaths() { export default function useLayoutAreas() { const { params } = useLocation(); const { postType, postId, path, layout, isCustom, canvas } = params; + const hasEditCanvasMode = canvas === 'edit'; useRedirectOldPaths(); // Page list @@ -91,13 +92,12 @@ export default function useLayoutAreas() { /> ), content: , - preview: ( isListLayout || canvas === 'edit' ) && , - mobile: - canvas === 'edit' ? ( - - ) : ( - - ), + preview: ( isListLayout || hasEditCanvasMode ) && , + mobile: hasEditCanvasMode ? ( + + ) : ( + + ), }, widths: { content: isListLayout ? 380 : undefined, @@ -115,8 +115,8 @@ export default function useLayoutAreas() { ), content: , - preview: ( isListLayout || canvas === 'edit' ) && , - mobile: , + preview: ( isListLayout || hasEditCanvasMode ) && , + mobile: hasEditCanvasMode ? : , }, widths: { content: isListLayout ? 380 : undefined, @@ -133,8 +133,8 @@ export default function useLayoutAreas() { areas: { sidebar: , content: , - mobile: , - preview: canvas === 'edit' && , + mobile: hasEditCanvasMode ? : , + preview: hasEditCanvasMode && , }, }; } @@ -148,7 +148,7 @@ export default function useLayoutAreas() { ), preview: , - mobile: canvas === 'edit' && , + mobile: hasEditCanvasMode && , }, }; } @@ -165,7 +165,7 @@ export default function useLayoutAreas() { /> ), preview: , - mobile: canvas === 'edit' && , + mobile: hasEditCanvasMode && , }, }; } @@ -176,7 +176,7 @@ export default function useLayoutAreas() { ), preview: , - mobile: canvas === 'edit' && , + mobile: hasEditCanvasMode && , }, }; } @@ -187,7 +187,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 bd56e30f10d11..37164690ed7fc 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(