Skip to content

Conversation

@GaryJones
Copy link
Contributor

Summary

Fixes the "Leave site? Changes you made may not be saved" warning appearing immediately on new posts when Custom Statuses is enabled, even when the user hasn't made any changes.

Root Cause

The block editor's subscribe handler was calling editPost() to set the default custom status on every new post. This marked the post as "dirty" (having unsaved changes) even though the user hadn't actually changed anything.

Solution

Check if the current status already matches the default before calling editPost(). This prevents the unnecessary edit that was triggering the dirty state.

// Before: Always called editPost()
if ( isCleanNewPost ) {
    dispatch( 'core/editor' ).editPost( { status: ef_default_custom_status } );
}

// After: Only call editPost() if status differs
if ( isCleanNewPost ) {
    const currentStatus = select( 'core/editor' ).getEditedPostAttribute( 'status' );
    if ( currentStatus !== ef_default_custom_status ) {
        dispatch( 'core/editor' ).editPost( { status: ef_default_custom_status } );
    }
}

Test plan

  1. Enable Custom Statuses module
  2. Create a new post in the block editor
  3. Without making any changes, try to close the tab or navigate away
  4. Verify no "Leave site?" warning appears
  5. Make an actual change, then try to leave - warning should appear

Closes #690

🤖 Generated with Claude Code

When creating a new post with Custom Statuses enabled, the block editor
would immediately show a "Leave site? Changes may not be saved" warning
even if the user hadn't made any changes.

This happened because the subscribe handler called editPost() to set
the default custom status, which marked the post as dirty. Now we check
if the status already matches the default before calling editPost().

Closes #690

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@GaryJones GaryJones requested a review from a team as a code owner December 23, 2025 17:43
@GaryJones GaryJones added this to the Next (minor) milestone Dec 23, 2025
@GaryJones GaryJones self-assigned this Dec 23, 2025
@GaryJones GaryJones merged commit 6dbf3ee into develop Dec 23, 2025
14 of 16 checks passed
@GaryJones GaryJones deleted the fix/690-leave-site-alert branch December 23, 2025 20:12
@GaryJones GaryJones mentioned this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leave site? Alert too aggressive when EditFlow and Custom Statuses is enabled.

2 participants