Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 1 addition & 13 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -149,7 +148,6 @@ export default function Editor( { listViewToggleElement, isLoading } ) {
),
};
}, [] );
const { setRenderingMode } = useDispatch( editorStore );

const isViewMode = canvasMode === 'view';
const isEditMode = canvasMode === 'edit';
Expand Down Expand Up @@ -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 ? <CanvasLoader id={ loadingProgressId } /> : null }
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
updateEditorSettings,
__experimentalTearDownEditor,
setCurrentTemplateId,
setRenderingMode,
} = unlock( useDispatch( editorStore ) );
const { createWarningNotice } = useDispatch( noticesStore );

Expand Down Expand Up @@ -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 ] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does setRenderingMode exist? Why not reuse settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it can be changed within the editor itself. the "settings" are something an external user of the EditorProvider component provides.


if ( ! isReady ) {
return null;
}
Expand Down