You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Block API: Change block mutation functions from undefined to noop in locked template #6587
Developer ExperienceIdeas about improving block and theme developer experience[Feature] Block APIAPI that allows to express the block paradigm.[Priority] LowUsed to indicate that the issue at hand isn't a top priority to address and can be handled later[Type] TaskIssues or PRs that have been broken down into an individual action to take
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.
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:
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.
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).
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.
Developer ExperienceIdeas about improving block and theme developer experience[Feature] Block APIAPI that allows to express the block paradigm.[Priority] LowUsed to indicate that the issue at hand isn't a top priority to address and can be handled later[Type] TaskIssues or PRs that have been broken down into an individual action to take
Activity
aduth commentedon Jul 3, 2018
Case in point, this currently throws an error when backspacing in a RichText in a locked template, because
onReplaceis not defined as a prop currently:gutenberg/core-blocks/paragraph/index.js
Line 280 in 47d6537
youknowriad commentedon Apr 19, 2019
Do we still want this? Should be a "Good first issue" right?
aduth commentedon Apr 29, 2019
There's some related discussion at #14712, specifically in that RichText relies on the presence (and non-presence) of
onReplaceto determine how it treats paste.gutenberg/packages/block-editor/src/components/rich-text/index.js
Line 286 in 5b3b3ab
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).
Mamaduka commentedon Apr 15, 2025
I'm going to close the issue. Why?