Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aduth opened this issue Apr 10, 2019 · 1 comment · Fixed by #14916
Closed

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

aduth opened this issue Apr 10, 2019 · 1 comment · Fixed by #14916
Labels
[Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Package] Block editor /packages/block-editor [Package] Editor /packages/editor [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended

Comments

@aduth
Copy link
Member

aduth commented Apr 10, 2019

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.

@aduth aduth added [Type] Bug An existing feature does not function as intended [Priority] High Used to indicate top priority items that need quick attention [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Package] Editor /packages/editor [Package] Block editor /packages/block-editor labels Apr 10, 2019
@aduth
Copy link
Member Author

aduth commented Apr 10, 2019

A plan I'm considering for moving forward:

Subsequently, we should follow-up with the more significant refactors of the reusable block to avoid needing to receive this blocks data into the block editor state, tracked at #7119 with related explorations at #14367 and #14715 ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Package] Block editor /packages/block-editor [Package] Editor /packages/editor [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant