Skip to content

Commit

Permalink
Spacer: Simplify the usage of `__unstableMarkNextChangeAsNotPersist…
Browse files Browse the repository at this point in the history
…ent`
  • Loading branch information
yogeshbhutkar committed Jan 24, 2025
1 parent c50b92a commit c053279
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/block-library/src/spacer/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,14 @@ const SpacerEdit = ( {
};

useEffect( () => {
__unstableMarkNextChangeAsNotPersistent();

if (
isFlexLayout &&
selfStretch !== 'fill' &&
selfStretch !== 'fit' &&
flexSize === undefined
) {
__unstableMarkNextChangeAsNotPersistent();
if ( inheritedOrientation === 'horizontal' ) {
// If spacer is moving from a vertical container to a horizontal container,
// it might not have width but have height instead.
Expand Down Expand Up @@ -305,7 +306,6 @@ const SpacerEdit = ( {
isFlexLayout &&
( selfStretch === 'fill' || selfStretch === 'fit' )
) {
__unstableMarkNextChangeAsNotPersistent();
if ( inheritedOrientation === 'horizontal' ) {
setAttributes( {
width: undefined,
Expand All @@ -317,16 +317,18 @@ const SpacerEdit = ( {
}
} else if ( ! isFlexLayout && ( selfStretch || flexSize ) ) {
if ( inheritedOrientation === 'horizontal' ) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( {
width: flexSize,
} );
} else {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( {
height: flexSize,
} );
}

// This ensures that the next change is not marked as persistent
// when the user changes the container layout.
__unstableMarkNextChangeAsNotPersistent();
setAttributes( {
style: {
...blockStyle,
Expand Down

0 comments on commit c053279

Please sign in to comment.