Skip to content

"Leave site?" alert too aggressive #46235

@jomurgel

Description

@jomurgel

Description

The "Leave site?" alert is too aggressive. When using the post type template argument for creating pre-defined block layouts for core/custom post types an entity edit is created { blocks: ... } which looking at the logic added in #24659 which only checks to see if the wp.data.select('core/editor').getPostEdits() return object has any keys, would ALWAYS return the "Leave site?" alert even if no other changes were made.

This is also true for any features that might make some update (create blocks, etc) with or without an undo level.

I would expect that the alert only changes if there are valid or manually-added changes to the new post. Or at the very least a title has been added or some non-default post content.

This is also a persistent change in the entity which means even after an update the blocks key exists in the entity object which would then ALWAY return the "Leave site?" alert, again, even though the post was just edited.

NOTE: Tests a brand new WP install no plugins active, installed. Tested filtering the post post type as well as with custom post types.

Entity added here:

const onChange = useCallback(

Check here: https://github.com/WordPress/gutenberg/pull/24659/files#diff-53f39da7a5f1f996f5359a2dd7b2747fb3d60a494523dd73dba946fab8e82592R102 for length, or https://github.com/WordPress/gutenberg/pull/24659/files#diff-8933c0b377d83066f7dde9c8b573bab9a7bfe60f73919e4e5e80aff92a88800cR119 which uses
select( coreStore ).hasEditsForEntityRecord(
which returns a length check here:

Step-by-step reproduction instructions

'template' => [
  [ 'core/paragraph' ],
  [ 'core/list' ],
],
  • "Add New" post that uses this template. Make not other edits.
  • In the console run wp.data.select('core/editor').getPostEdits() and confirm the existence of blocks in the entity. Something like { blocks: ... }.
  • Confirm also that when leaving the page by either clicking out of the editor or trying to close the tab that the "Leave site?" alert is present.
  • Confirm multiple times.
  • Remove the template. Confirm that the behavior above does not take place if a template is not present.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.1.1
  • All Browsers
  • Macbook Pro M1 | macOs 12.4

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

Yes

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

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Templates APIRelated to API powering block template functionality in the Site Editor

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions