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

Custom post type lock breaks block recovery #49005

Open
Tropicalista opened this issue Mar 11, 2023 · 4 comments
Open

Custom post type lock breaks block recovery #49005

Tropicalista opened this issue Mar 11, 2023 · 4 comments
Labels
[Feature] Block Locking The API allowing for the ability to lock/unlock blocks [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Type] Bug An existing feature does not function as intended

Comments

@Tropicalista
Copy link

Description

Adding a template lock can break the block recovery.

This line prevent block recovery:

const isLocked = !! getTemplateLock( state, rootClientId );

Step-by-step reproduction instructions

  1. Create a custom post type with a template core/group
  2. Add template_lock: 'insert'
  3. Create new custom post type and add a paragraph or whatever
  4. In the code editor change markup of core/group addin something like data-foo="bar"
  5. The block is invalid.
  6. Try to recovery block and nothing happens

Do the same steps on a normal post/page. The recovery works great if you try the recovery on a post/page.

Screenshots, screen recording, code snippet

No response

Environment info

No response

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

@Tropicalista
Copy link
Author

The expected behaviour is to recovery the block. However this is not possible due to a lock.
But recovery does not insert new block. It just replace the existing one with same attributes. The lock check should be bypassed in this case.

@gziolo gziolo added [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Feature] Block Locking The API allowing for the ability to lock/unlock blocks Needs Testing Needs further testing to be confirmed. labels Mar 12, 2023
@kathrynwp kathrynwp added the [Type] Enhancement A suggestion for improvement. label Mar 13, 2023
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. Needs Testing Needs further testing to be confirmed. labels Mar 15, 2023
@Mamaduka
Copy link
Member

I can reproduce the issue.

When a template is locked, we should probably do a more granular check inside canInsertBlockTypeUnmemoized. Maybe something similar to validateBlocksToTemplate.

@talldan
Copy link
Contributor

talldan commented Mar 15, 2023

When a template is locked, we should probably do a more granular check inside canInsertBlockTypeUnmemoized. Maybe something similar to validateBlocksToTemplate.

Yeah, it's a difficult one to solve. canInsertBlockType has no knowledge of the block being replaced, it just knows that the parent block is locked and so we can't insert the recovered block.

Maybe introducing a canReplaceBlock selector that does a slightly different check and accounts for block validity, would be the way forwards.

An observation - I notice that when an invalid block has 'prevent removal' active, it can still be recovered 🤔

@Tropicalista
Copy link
Author

@talldan exactly what I was thinking: introduce a canReplaceBlock can also be used to insert pattern.

For example if pattern selected match root block, it will be replaced, otherwise skipped.

Another solution can be to introduce a block limit count on post type that will act as a locker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Locking The API allowing for the ability to lock/unlock blocks [Feature] Block Validation/Deprecation Handling block validation to determine accuracy and deprecation [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants