From a2d1d37a1ad803c92645220a3afa45fe1dc2459e Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 6 Dec 2023 15:19:41 +0100 Subject: [PATCH] Editor: Cleanup default editor mode handling (#56819) --- packages/edit-post/src/editor.js | 8 +------- packages/edit-site/src/components/editor/index.js | 14 +------------- packages/editor/src/components/provider/index.js | 6 ++++++ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 2394ebb3a3a742..cff867c3f7a2cb 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -9,7 +9,7 @@ import { store as editorStore, privateApis as editorPrivateApis, } from '@wordpress/editor'; -import { useEffect, useMemo } from '@wordpress/element'; +import { useMemo } from '@wordpress/element'; import { SlotFillProvider } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; import { store as preferencesStore } from '@wordpress/preferences'; @@ -142,12 +142,6 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) { keepCaretInsideBlock, ] ); - // The default mode of the post editor is "post-only" mode. - const { setRenderingMode } = useDispatch( editorStore ); - useEffect( () => { - setRenderingMode( 'post-only' ); - }, [ setRenderingMode ] ); - if ( ! post ) { return null; } diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index 1d3fca36f5f4c0..5a2f1e2ec4d1a9 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect, useDispatch } from '@wordpress/data'; +import { useSelect } from '@wordpress/data'; import { Notice } from '@wordpress/components'; import { useInstanceId } from '@wordpress/compose'; import { store as preferencesStore } from '@wordpress/preferences'; @@ -29,7 +29,6 @@ import { } from '@wordpress/editor'; import { __, sprintf } from '@wordpress/i18n'; import { store as coreDataStore } from '@wordpress/core-data'; -import { useEffect } from '@wordpress/element'; /** * Internal dependencies @@ -149,7 +148,6 @@ export default function Editor( { listViewToggleElement, isLoading } ) { ), }; }, [] ); - const { setRenderingMode } = useDispatch( editorStore ); const isViewMode = canvasMode === 'view'; const isEditMode = canvasMode === 'edit'; @@ -192,16 +190,6 @@ export default function Editor( { listViewToggleElement, isLoading } ) { ( ( postWithTemplate && !! contextPost && !! editedPost ) || ( ! postWithTemplate && !! editedPost ) ); - // This is the only reliable way I've found to reinitialize the rendering mode - // when the canvas mode or the edited entity changes. - useEffect( () => { - if ( canvasMode === 'edit' && postWithTemplate ) { - setRenderingMode( 'template-locked' ); - } else { - setRenderingMode( 'all' ); - } - }, [ canvasMode, postWithTemplate, setRenderingMode ] ); - return ( <> { ! isReady ? : null } diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 3bd5860501d4e0..3e32c7f80f48e1 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -199,6 +199,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( updateEditorSettings, __experimentalTearDownEditor, setCurrentTemplateId, + setRenderingMode, } = unlock( useDispatch( editorStore ) ); const { createWarningNotice } = useDispatch( noticesStore ); @@ -243,6 +244,11 @@ export const ExperimentalEditorProvider = withRegistryProvider( setCurrentTemplateId( template?.id ); }, [ template?.id, setCurrentTemplateId ] ); + // Sets the right rendering mode when loading the editor. + useEffect( () => { + setRenderingMode( settings.defaultRenderingMode ?? 'post-only' ); + }, [ settings.defaultRenderingMode, setRenderingMode ] ); + if ( ! isReady ) { return null; }