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

Removing a Template Part dirties the entity state with inner content removed. #22638

Closed
Addison-Stavlo opened this issue May 26, 2020 · 2 comments · Fixed by #22586
Closed

Removing a Template Part dirties the entity state with inner content removed. #22638

Addison-Stavlo opened this issue May 26, 2020 · 2 comments · Fixed by #22586
Labels
[Type] Bug An existing feature does not function as intended

Comments

@Addison-Stavlo
Copy link
Contributor

Describe the bug
Removing a Template Part from a page results in the Template Part edited to clear all inner content. This is a 'recent' regression in behavior. @noahtallen mentioned this is likely related to a recent PR of his (#21368 ).

To reproduce
Steps to reproduce the behavior:

  1. Go to an Edtior (shown below is page editor) with full site editing experiment enabled.
  2. insert a Template Part.
  3. remove the template part.
  4. notice the template part is 'dirty' in the save panel, and re-inserting will result in an empty template part.

Expected behavior
Expect the template part to not be dirtied on removal.

Screenshots

deleting-template-part-bug

@Addison-Stavlo Addison-Stavlo added [Type] Bug An existing feature does not function as intended [Feature] Full Site Editing labels May 26, 2020
@noahtallen
Copy link
Member

noahtallen commented May 26, 2020

Now that I think about it, #22586 will resolve this! 🥳

This is what causes the bug:

  1. Removing the block triggers the remove block action in the block-editor store
  2. The block-editor store removes all inner blocks of the given block
  3. The useBlockSync hook for the the template part sees all of its inner blocks being removed and syncs those changes to the controlling entity.
  4. The template part entity's content is wiped, triggering the dirty state (and saving will persist the wipe)
  5. The useBlockSync hook "unsubscribes" now that the block associated with it is not in the editor.

So the solution is to "unsubscribe" from the changes a lot earlier. @epiqueras caught this as well in #22586, which cleans up that lingering subscription before it has a chance to cause issues.

@Addison-Stavlo
Copy link
Contributor Author

Oh Nice! Im glad this has already been noticed and has a solution 😄

@Addison-Stavlo Addison-Stavlo changed the title Removing a Template Part dirty's the entity state with inner content removed. Removing a Template Part dirties the entity state with inner content removed. May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants