diff --git a/packages/block-editor/src/components/provider/index.js b/packages/block-editor/src/components/provider/index.js index dbd646426718d..13d25aafd8c83 100644 --- a/packages/block-editor/src/components/provider/index.js +++ b/packages/block-editor/src/components/provider/index.js @@ -28,9 +28,16 @@ export const ExperimentalBlockEditorProvider = withRegistryProvider( ...settings, __internalIsInitialized: true, }, - stripExperimentalSettings + { + stripExperimentalSettings, + reset: true, + } ); - }, [ settings ] ); + }, [ + settings, + stripExperimentalSettings, + __experimentalUpdateSettings, + ] ); // Syncs the entity provider with changes in the block-editor store. useBlockSync( props ); diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index 09ff7e185ab54..9dd3b24009c51 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1390,7 +1390,9 @@ export function updateBlockListSettings( clientId, settings ) { * @return {Object} Action object */ export function updateSettings( settings ) { - return __experimentalUpdateSettings( settings, true ); + return __experimentalUpdateSettings( settings, { + stripExperimentalSettings: true, + } ); } /** diff --git a/packages/block-editor/src/store/private-actions.js b/packages/block-editor/src/store/private-actions.js index 74c83d6018969..8b5e066e5a83c 100644 --- a/packages/block-editor/src/store/private-actions.js +++ b/packages/block-editor/src/store/private-actions.js @@ -28,13 +28,15 @@ const privateSettings = [ * Action that updates the block editor settings and * conditionally preserves the experimental ones. * - * @param {Object} settings Updated settings - * @param {boolean} stripExperimentalSettings Whether to strip experimental settings. + * @param {Object} settings Updated settings + * @param {Object} options Options object. + * @param {boolean} options.stripExperimentalSettings Whether to strip experimental settings. + * @param {boolean} options.reset Whether to reset the settings. * @return {Object} Action object */ export function __experimentalUpdateSettings( settings, - stripExperimentalSettings = false + { stripExperimentalSettings = false, reset = false } = {} ) { let cleanSettings = settings; // There are no plugins in the mobile apps, so there is no @@ -50,6 +52,7 @@ export function __experimentalUpdateSettings( return { type: 'UPDATE_SETTINGS', settings: cleanSettings, + reset, }; } diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index d23f5f3058978..b4104a69ac620 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -1623,6 +1623,12 @@ export function template( state = { isValid: true }, action ) { export function settings( state = SETTINGS_DEFAULTS, action ) { switch ( action.type ) { case 'UPDATE_SETTINGS': + if ( action.reset ) { + return { + ...SETTINGS_DEFAULTS, + ...action.settings, + }; + } return { ...state, ...action.settings, diff --git a/packages/block-editor/src/store/test/private-actions.js b/packages/block-editor/src/store/test/private-actions.js index fdfe993091fef..01f6b85f5f9aa 100644 --- a/packages/block-editor/src/store/test/private-actions.js +++ b/packages/block-editor/src/store/test/private-actions.js @@ -6,6 +6,7 @@ import { showBlockInterface, setBlockEditingMode, unsetBlockEditingMode, + __experimentalUpdateSettings, } from '../private-actions'; describe( 'private actions', () => { @@ -50,4 +51,59 @@ describe( 'private actions', () => { } ); } ); } ); + + describe( '__experimentalUpdateSettings', () => { + const experimentalSettings = { + inserterMediaCategories: 'foo', + blockInspectorAnimation: 'bar', + }; + + const stableSettings = { + foo: 'foo', + bar: 'bar', + baz: 'baz', + }; + + const settings = { + ...experimentalSettings, + ...stableSettings, + }; + + it( 'should dispatch provided settings by default', () => { + expect( __experimentalUpdateSettings( settings ) ).toEqual( { + type: 'UPDATE_SETTINGS', + settings, + reset: false, + } ); + } ); + + it( 'should dispatch provided settings with reset flag when `reset` argument is truthy', () => { + expect( + __experimentalUpdateSettings( settings, { + stripExperimentalSettings: false, + reset: true, + } ) + ).toEqual( { + type: 'UPDATE_SETTINGS', + settings, + reset: true, + } ); + } ); + + it( 'should strip experimental settings from a given settings object when `stripExperimentalSettings` argument is truthy', () => { + expect( + __experimentalUpdateSettings( settings, { + stripExperimentalSettings: true, + } ) + ).toEqual( { + type: 'UPDATE_SETTINGS', + settings: { + foo: 'foo', + bar: 'bar', + baz: 'baz', + }, + reset: false, + } ); + } ); + } ); } ); diff --git a/packages/edit-site/src/components/block-editor/use-site-editor-settings.js b/packages/edit-site/src/components/block-editor/use-site-editor-settings.js index af3f5ccba3498..4ce186ad9d6bb 100644 --- a/packages/edit-site/src/components/block-editor/use-site-editor-settings.js +++ b/packages/edit-site/src/components/block-editor/use-site-editor-settings.js @@ -78,14 +78,6 @@ export default function useSiteEditorSettings( templateType ) { inserterMediaCategories, __experimentalBlockPatterns: blockPatterns, __experimentalBlockPatternCategories: blockPatternCategories, - // Temporary fix for bug in Block Editor Provider: - // see: https://github.com/WordPress/gutenberg/issues/51489. - // Some Site Editor entities (e.g. `wp_navigation`) may utilise - // template locking in their settings. Therefore this must be - // explicitly "unset" to avoid the template locking UI remaining - // active for all entities. - templateLock: false, - template: false, }; }, [ storedSettings, blockPatterns, blockPatternCategories ] ); }