Skip to content

Block API: Change block mutation functions from undefined to noop in locked template #6587

Closed as not planned

Description

@aduth

Previously: https://github.com/WordPress/gutenberg/pull/3686/files#r185262287

Currently, a block implementer may need to anticipate that any of the following functions may be undefined if the post template is locked for editing:

  • insertBlocksAfter
  • onReplace
  • mergeBlocks

Instead of placing the burden on the developer to differentiate between the type, we should simply pass it as a function regardless of whether the template is locked. If it is a locked template, the function should effectively be a noop.

Open questions:

  • Are there valid use cases where a block implementer may legitimately want to distinguish characteristics of the block depending on whether the template is locked or not? This information is still available via withSelect, and could additionally be passed as a prop to the block's edit component.

Activity

  1. added
    [Feature] Block API
    [Type] Task
    on May 4, 2018
  2. aduth commented on Jul 3, 2018

    @aduth
    MemberAuthor

    Case in point, this currently throws an error when backspacing in a RichText in a locked template, because onReplace is not defined as a prop currently:

    onRemove={ () => onReplace( [] ) }

  3. youknowriad commented on Apr 19, 2019

    @youknowriad
    Contributor

    Do we still want this? Should be a "Good first issue" right?

  4. aduth commented on Apr 29, 2019

    @aduth
    MemberAuthor

    There's some related discussion at #14712, specifically in that RichText relies on the presence (and non-presence) of onReplace to determine how it treats paste.

    const shouldReplace = this.props.onReplace && this.isEmpty();

    I think the improvements proposed by this issue would make for a good developer experience improvement, though I'd acknowledge it's a minor issue, and that a resolution may not be as trivial as first considered based on this new information from #14712 (review).

  5. added
    [Priority] Low
    on Apr 29, 2019
  6. added
    Developer Experience
    on Jul 11, 2022
  7. Mamaduka commented on Apr 15, 2025

    @Mamaduka
    Member

    I'm going to close the issue. Why?

    • RichText still relies on this old behavior.
    • It's been six years, and at this point, the proposed change might count as breaking change. We can't assume that consumer code doesn't rely on logic similar to RichText components.
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

    Developer Experience[Feature] Block API[Priority] Low[Type] Task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions