Skip to content

Commit 2cee795

Browse files
ramonjdandrewserongyouknowriadt-hamanopriethor
committed
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 <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: priethor <priethor@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org> Co-authored-by: ironprogrammer <ironprogrammer@git.wordpress.org> Co-authored-by: ivan-ottinger <ivanottinger@git.wordpress.org> Co-authored-by: mrfoxtalbot <mrfoxtalbot@git.wordpress.org>
1 parent 7398659 commit 2cee795

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

packages/edit-site/src/components/layout/router.js

+23-15
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default function useLayoutAreas() {
7777
const isSiteEditorLoading = useIsSiteEditorLoading();
7878
const { params } = useLocation();
7979
const { postType, postId, path, layout, isCustom, canvas } = params;
80+
const hasEditCanvasMode = canvas === 'edit';
8081
useRedirectOldPaths();
8182

8283
// Page list
@@ -93,15 +94,14 @@ export default function useLayoutAreas() {
9394
/>
9495
),
9596
content: <PagePages />,
96-
preview: ( isListLayout || canvas === 'edit' ) && (
97+
preview: ( isListLayout || hasEditCanvasMode ) && (
9798
<Editor isLoading={ isSiteEditorLoading } />
9899
),
99-
mobile:
100-
canvas === 'edit' ? (
101-
<Editor isLoading={ isSiteEditorLoading } />
102-
) : (
103-
<PagePages />
104-
),
100+
mobile: hasEditCanvasMode ? (
101+
<Editor isLoading={ isSiteEditorLoading } />
102+
) : (
103+
<PagePages />
104+
),
105105
},
106106
widths: {
107107
content: isListLayout ? 380 : undefined,
@@ -119,10 +119,14 @@ export default function useLayoutAreas() {
119119
<SidebarNavigationScreenTemplatesBrowse backPath={ {} } />
120120
),
121121
content: <PageTemplates />,
122-
preview: ( isListLayout || canvas === 'edit' ) && (
122+
preview: ( isListLayout || hasEditCanvasMode ) && (
123123
<Editor isLoading={ isSiteEditorLoading } />
124124
),
125-
mobile: <PageTemplates />,
125+
mobile: hasEditCanvasMode ? (
126+
<Editor isLoading={ isSiteEditorLoading } />
127+
) : (
128+
<PageTemplates />
129+
),
126130
},
127131
widths: {
128132
content: isListLayout ? 380 : undefined,
@@ -139,8 +143,12 @@ export default function useLayoutAreas() {
139143
areas: {
140144
sidebar: <SidebarNavigationScreenPatterns backPath={ {} } />,
141145
content: <PagePatterns />,
142-
mobile: <PagePatterns />,
143-
preview: canvas === 'edit' && (
146+
mobile: hasEditCanvasMode ? (
147+
<Editor isLoading={ isSiteEditorLoading } />
148+
) : (
149+
<PagePatterns />
150+
),
151+
preview: hasEditCanvasMode && (
144152
<Editor isLoading={ isSiteEditorLoading } />
145153
),
146154
},
@@ -156,7 +164,7 @@ export default function useLayoutAreas() {
156164
<SidebarNavigationScreenGlobalStyles backPath={ {} } />
157165
),
158166
preview: <Editor isLoading={ isSiteEditorLoading } />,
159-
mobile: canvas === 'edit' && (
167+
mobile: hasEditCanvasMode && (
160168
<Editor isLoading={ isSiteEditorLoading } />
161169
),
162170
},
@@ -175,7 +183,7 @@ export default function useLayoutAreas() {
175183
/>
176184
),
177185
preview: <Editor isLoading={ isSiteEditorLoading } />,
178-
mobile: canvas === 'edit' && (
186+
mobile: hasEditCanvasMode && (
179187
<Editor isLoading={ isSiteEditorLoading } />
180188
),
181189
},
@@ -188,7 +196,7 @@ export default function useLayoutAreas() {
188196
<SidebarNavigationScreenNavigationMenus backPath={ {} } />
189197
),
190198
preview: <Editor isLoading={ isSiteEditorLoading } />,
191-
mobile: canvas === 'edit' && (
199+
mobile: hasEditCanvasMode && (
192200
<Editor isLoading={ isSiteEditorLoading } />
193201
),
194202
},
@@ -201,7 +209,7 @@ export default function useLayoutAreas() {
201209
areas: {
202210
sidebar: <SidebarNavigationScreenMain />,
203211
preview: <Editor isLoading={ isSiteEditorLoading } />,
204-
mobile: canvas === 'edit' && (
212+
mobile: hasEditCanvasMode && (
205213
<Editor isLoading={ isSiteEditorLoading } />
206214
),
207215
},

packages/edit-site/src/store/private-actions.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { store as editorStore } from '@wordpress/editor';
1313
export const setCanvasMode =
1414
( mode ) =>
1515
( { registry, dispatch } ) => {
16+
const isMediumOrBigger =
17+
window.matchMedia( '(min-width: 782px)' ).matches;
1618
const switchCanvasMode = () => {
1719
registry.batch( () => {
18-
const isMediumOrBigger =
19-
window.matchMedia( '(min-width: 782px)' ).matches;
2020
registry.dispatch( blockEditorStore ).clearSelectedBlock();
2121
registry.dispatch( editorStore ).setDeviceType( 'Desktop' );
2222
registry
@@ -59,7 +59,11 @@ export const setCanvasMode =
5959
} );
6060
};
6161

62-
if ( ! document.startViewTransition ) {
62+
/*
63+
* Skip transition in mobile, otherwise it crashes the browser.
64+
* See: https://github.com/WordPress/gutenberg/pull/63002.
65+
*/
66+
if ( ! isMediumOrBigger || ! document.startViewTransition ) {
6367
switchCanvasMode();
6468
} else {
6569
document.documentElement.classList.add(

0 commit comments

Comments
 (0)