Skip to content

Custom post type lock breaks block recovery #49005

Closed

Description

@Tropicalista

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

Activity

  1. Tropicalista commented on Mar 11, 2023

    @Tropicalista
    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.

  2. added
    [Type] BugAn existing feature does not function as intended
    and removed
    Needs TestingNeeds further testing to be confirmed.
    on Mar 15, 2023
  3. Mamaduka commented on Mar 15, 2023

    @Mamaduka
    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.

  4. talldan commented on Mar 15, 2023

    @talldan
    Contributor

    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 🤔

  5. Tropicalista commented on Mar 15, 2023

    @Tropicalista
    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.

  6. youknowriad commented on Sep 17, 2026

    @youknowriad
    Contributor

    Still reproduces on trunk (recovery does nothing under a template lock, works without one). This is the same root cause as #25216, so closing as a duplicate to keep it in one place.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block LockingThe API allowing for the ability to lock/unlock blocks[Feature] Block Validation/DeprecationHandling block validation to determine accuracy and deprecation[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