Skip to content

Commit

Permalink
Site Editor: patterns and templates cannot be edited from sidebar mob…
Browse files Browse the repository at this point in the history
…ile 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 <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: priethor <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: ironprogrammer <[email protected]>
Co-authored-by: ivan-ottinger <[email protected]>
Co-authored-by: mrfoxtalbot <[email protected]>
  • Loading branch information
10 people committed Jul 2, 2024
1 parent 7398659 commit 2cee795
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
38 changes: 23 additions & 15 deletions packages/edit-site/src/components/layout/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -93,15 +94,14 @@ export default function useLayoutAreas() {
/>
),
content: <PagePages />,
preview: ( isListLayout || canvas === 'edit' ) && (
preview: ( isListLayout || hasEditCanvasMode ) && (
<Editor isLoading={ isSiteEditorLoading } />
),
mobile:
canvas === 'edit' ? (
<Editor isLoading={ isSiteEditorLoading } />
) : (
<PagePages />
),
mobile: hasEditCanvasMode ? (
<Editor isLoading={ isSiteEditorLoading } />
) : (
<PagePages />
),
},
widths: {
content: isListLayout ? 380 : undefined,
Expand All @@ -119,10 +119,14 @@ export default function useLayoutAreas() {
<SidebarNavigationScreenTemplatesBrowse backPath={ {} } />
),
content: <PageTemplates />,
preview: ( isListLayout || canvas === 'edit' ) && (
preview: ( isListLayout || hasEditCanvasMode ) && (
<Editor isLoading={ isSiteEditorLoading } />
),
mobile: <PageTemplates />,
mobile: hasEditCanvasMode ? (
<Editor isLoading={ isSiteEditorLoading } />
) : (
<PageTemplates />
),
},
widths: {
content: isListLayout ? 380 : undefined,
Expand All @@ -139,8 +143,12 @@ export default function useLayoutAreas() {
areas: {
sidebar: <SidebarNavigationScreenPatterns backPath={ {} } />,
content: <PagePatterns />,
mobile: <PagePatterns />,
preview: canvas === 'edit' && (
mobile: hasEditCanvasMode ? (
<Editor isLoading={ isSiteEditorLoading } />
) : (
<PagePatterns />
),
preview: hasEditCanvasMode && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
Expand All @@ -156,7 +164,7 @@ export default function useLayoutAreas() {
<SidebarNavigationScreenGlobalStyles backPath={ {} } />
),
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile: canvas === 'edit' && (
mobile: hasEditCanvasMode && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
Expand All @@ -175,7 +183,7 @@ export default function useLayoutAreas() {
/>
),
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile: canvas === 'edit' && (
mobile: hasEditCanvasMode && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
Expand All @@ -188,7 +196,7 @@ export default function useLayoutAreas() {
<SidebarNavigationScreenNavigationMenus backPath={ {} } />
),
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile: canvas === 'edit' && (
mobile: hasEditCanvasMode && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
Expand All @@ -201,7 +209,7 @@ export default function useLayoutAreas() {
areas: {
sidebar: <SidebarNavigationScreenMain />,
preview: <Editor isLoading={ isSiteEditorLoading } />,
mobile: canvas === 'edit' && (
mobile: hasEditCanvasMode && (
<Editor isLoading={ isSiteEditorLoading } />
),
},
Expand Down
10 changes: 7 additions & 3 deletions packages/edit-site/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2cee795

Please sign in to comment.