Skip to content

Commit

Permalink
Editor: Cleanup default editor mode handling (#56819)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Dec 6, 2023
1 parent efa4b01 commit a2d1d37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
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 ] );

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

1 comment on commit a2d1d37

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in a2d1d37.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7115786663
📝 Reported issues:

Please sign in to comment.