Skip to content

Block Editor: Reusable blocks fetching causes "Unsaved Changes" prompt #14910

Closed

Description

Related: #14766

Describe the bug

Any action which triggers reusable blocks to become fetched will trigger the editor's mechanism to prompt the user when they leave the page.

This includes:

  • Fetch as a result of autocompleters (selecting any paragraph block)
  • Fetch as a result of toggling the Inserter
  • Fetch as a result of a reusable block being present in the post's content

To reproduce

  1. Navigate to Posts > Add New
  2. Add a paragraph
  3. Save the post
  4. Reload the page
  5. Select the paragraph block
  6. Reload the page, or attempt to navigate away
  7. Observe the prompt

Or:

  1. Navigate to Posts > Add New
  2. Click the inserter
  3. Reload the page, or attempt to navigate away
  4. Observe the prompt

Or:

  1. Navigate to Posts > Add New
  2. Insert a reusable block
  3. Save the post
  4. Reload the page
  5. Reload the page, or attempt to navigate away
  6. Observe the prompt

Expected behavior

A prompt should not be shown.

Additional context

There is a fair amount of debugging information available at:

Specifically, the comment at #14766 (comment) describe that the reason this occurs is that when the block editor receives reusable blocks as a result of the fetch, it considers this a change in its own state, which surfaces up to the editor and is accounted for in considering to show the prompt upon leaving the page.

It is not easy to solve because:

  • RECEIVE_BLOCKS may in-fact include dirtying changes, so it cannot be skipped for consideration in whether the BlockEditorProvider call the onInput or onChange props.
  • The block editor module must receive blocks data for the reusable blocks, otherwise it cannot be shown in the editor (the implementation of the reusable block uses select( 'core/block-editor' ).getBlock).
  • It can't be done as part of the normal "sync" operations between editor and block editor because technically these reusable blocks are not part of the blocks value (they are not necessarily in post content).

Ultimately this ties into the issues of #7119 and related explorations at #14367 and #14715 , where the block editor state is not responsible for holding data of the reusable blocks. These however are much larger tasks, and a more immediate fix should be explored.

I am currently considering a fix which would update the blocks autocompleter to trigger the reusable blocks fetch only when generating its own options. However, as noted above, this only accounts for one of three possible workflows to trigger reusable blocsk fetching.

cc @youknowriad in case you have thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    [Feature] Synced PatternsRelated to synced patterns (formerly reusable blocks)[Package] Block editor/packages/block-editor[Package] Editor/packages/editor[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions