diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 4b8a3b6b23c25..0a2bf523c2c5d 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -189,13 +189,17 @@ export const ExperimentalEditorProvider = withRegistryProvider( coreStore ).hasFinishedResolution( 'getPostType', [ post.type ] ); + const renderingMode = getRenderingMode(); + return { hasLoadedPostObject: _hasLoadedPostObject, editorSettings: getEditorSettings(), isReady: __unstableIsEditorReady(), - mode: getRenderingMode(), + mode: renderingMode, defaultMode: - postTypeObject?.default_rendering_mode ?? 'post-only', + renderingMode ?? + postTypeObject?.default_rendering_mode ?? + 'post-only', selection: getEditorSelection(), postTypeEntities: post.type === 'wp_template' @@ -327,8 +331,13 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Sets the right rendering mode when loading the editor. useEffect( () => { + // If mode equals default mode, rendering mode is already set appropriately. + if ( mode === defaultMode ) { + return; + } + setRenderingMode( defaultMode ); - }, [ defaultMode, setRenderingMode ] ); + }, [ mode, defaultMode, setRenderingMode ] ); useHideBlocksFromInserter( post.type, mode ); diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index 9d0de08718cd2..191f994f9fa4a 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -663,10 +663,9 @@ export const setRenderingMode = dispatch.editPost( { selection: undefined }, { undoIgnore: true } ); } - dispatch( { - type: 'SET_RENDERING_MODE', - mode, - } ); + registry + .dispatch( preferencesStore ) + .set( 'core', 'renderingMode', mode ); }; /** diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index a165d90e296d6..882b29730750b 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -267,15 +267,6 @@ export function editorSettings( state = EDITOR_SETTINGS_DEFAULTS, action ) { return state; } -export function renderingMode( state = 'post-only', action ) { - switch ( action.type ) { - case 'SET_RENDERING_MODE': - return action.mode; - } - - return state; -} - /** * Reducer returning the editing canvas device type. * @@ -395,7 +386,6 @@ export default combineReducers( { postSavingLock, editorSettings, postAutosavingLock, - renderingMode, deviceType, removedPanels, blockInserterPanel, diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 4ab0a47210353..b99390c170985 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1287,9 +1287,9 @@ export function getEditorSettings( state ) { * * @return {string} Rendering mode. */ -export function getRenderingMode( state ) { - return state.renderingMode; -} +export const getRenderingMode = createRegistrySelector( ( select ) => () => { + return select( preferencesStore ).get( 'core', 'renderingMode' ); +} ); /** * Returns the current editing canvas device type.