Skip to content

Commit

Permalink
Interface: don't persist default complementary area on load
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 3, 2024
1 parent 9addc70 commit ba8f57f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
11 changes: 7 additions & 4 deletions packages/interface/src/components/complementary-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,13 @@ function ComplementaryArea( {
useEffect( () => {
// Set initial visibility: For large screens, enable if it's active by
// default. For small screens, always initially disable.
if ( isActiveByDefault && activeArea === undefined && ! isSmall ) {
enableComplementaryArea( scope, identifier );
} else if ( activeArea === undefined && isSmall ) {
disableComplementaryArea( scope, identifier );
if ( activeArea === undefined ) {
const args = [ scope, identifier, { persist: false } ];
if ( isActiveByDefault && ! isSmall ) {
enableComplementaryArea( ...args );
} else if ( isSmall ) {
disableComplementaryArea( ...args );
}
}
setIsReady( true );
}, [
Expand Down
24 changes: 14 additions & 10 deletions packages/interface/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export const setDefaultComplementaryArea = ( scope, area ) => {
/**
* Enable the complementary area.
*
* @param {string} scope Complementary area scope.
* @param {string} area Area identifier.
* @param {string} scope Complementary area scope.
* @param {string} area Area identifier.
* @param {Object} options Options.
* @param {boolean} options.persist Whether to persist.
*/
export const enableComplementaryArea =
( scope, area ) =>
( scope, area, { persist = true } = {} ) =>
( { registry, dispatch } ) => {
// Return early if there's no area.
if ( ! area ) {
Expand All @@ -46,14 +48,16 @@ export const enableComplementaryArea =
scope = normalizeComplementaryAreaScope( scope );
area = normalizeComplementaryAreaName( scope, area );

const isComplementaryAreaVisible = registry
.select( preferencesStore )
.get( scope, 'isComplementaryAreaVisible' );
if ( persist ) {
const isComplementaryAreaVisible = registry
.select( preferencesStore )
.get( scope, 'isComplementaryAreaVisible' );

if ( ! isComplementaryAreaVisible ) {
registry
.dispatch( preferencesStore )
.set( scope, 'isComplementaryAreaVisible', true );
if ( ! isComplementaryAreaVisible ) {
registry
.dispatch( preferencesStore )
.set( scope, 'isComplementaryAreaVisible', true );
}
}

dispatch( {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/specs/site-editor/preload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ test.describe( 'Preload', () => {
// There are two separate settings OPTIONS requests. We should fix
// so the one for canUser and getEntityRecord are reused.
'/wp/v2/settings',
// Seems to be coming from `enableComplementaryArea`.
'/wp/v2/users/me',
] );
} );
} );

0 comments on commit ba8f57f

Please sign in to comment.