WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Spacer block, when used as Grow(Fill) or Fit, will prompt a user about unsaved changes when navigating away, even when no unsaved changes #67041

Open MadtownLems opened 4 hours ago

MadtownLems commented 4 hours ago

Description

When you leave the Post Editor of content that contains a Spacer Block set to either Grow (previously Fill) or Fit, the browser will warn you about losing unsaved changes, even if you haven't changed anything. The issue does not impact Spacer Blocks that have a Fixed height.

Step-by-step reproduction instructions

  1. Create a new Post.
  2. Insert a Stack.
  3. Insert a Spacer within the Stack.
  4. Set it to Grow.
  5. Publish.
  6. Go back to your All Posts list.
  7. Return to editing the Post.
  8. Make no changes, but navigate away.
  9. See that you were warned about unsaved changes (even though you didn't make any)

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.6.2 and WordPress 6.7. Theme: Twenty Twenty Four (and others). No Gutenberg plugin.

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Please confirm which theme type you used for testing.

Mayank-Tripathi32 commented 2 hours ago

Hello,

Thank you for reporting this bug.

I have verified that the issue occurs with grow and fit, but it works fine with fixed width. I’ll now investigate possible solutions.

Thanks!

Mayank-Tripathi32 commented 2 hours ago

I’ve identified the problem—it originates from the useEffect running on load and updating attributes:

if (  isFlexLayout && ( selfStretch === 'fill' || selfStretch === 'fit' )) {

    if ( inheritedOrientation === 'horizontal' ) {
        setAttributes( {
            width: undefined,
        } );
    }  else {
        setAttributes( {
            height: undefined,
        } );
    }
}

I’ll investigate further to determine whether this can be removed or if additional checks are needed.

Mayank-Tripathi32 commented 2 hours ago

I’ve identified the problem—it originates from the useEffect running on load and updating attributes:

if ( isFlexLayout && ( selfStretch === 'fill' || selfStretch === 'fit' )) {

if ( inheritedOrientation === 'horizontal' ) { setAttributes( { width: undefined, } ); } else { setAttributes( { height: undefined, } ); } } I’ll investigate further to determine whether this can be removed or if additional checks are needed.

I believe adding a check && width !== undefined resolves the issue. I’ll proceed with opening a PR to address this.