Skip to content

RichText: don't apply input transform when there's no onReplace - #80978

Merged
jsnajdr merged 1 commit into
trunkfrom
fix/rich-text-transform-onreplace
Jul 30, 2026
Merged

RichText: don't apply input transform when there's no onReplace#80978
jsnajdr merged 1 commit into
trunkfrom
fix/rich-text-transform-onreplace

Conversation

@jsnajdr

@jsnajdr jsnajdr commented Jul 30, 2026

Copy link
Copy Markdown
Member

Fixes a crash when a RichText field wants to apply an input transform, but there is no onReplace handler that would execute the transform, i.e., replace the current block with another one.

Steps to reproduce:

  1. Create a core/pullquote block that has a field with text, but no ability to contain inner blocks. Or a locked core/paragraph, with locked removal.
  2. Type --- inside. This would normally convert the block to a separator, but in these cases the new block can't be created.
  3. There is a crash:
Screenshot 2026-07-30 at 16 39 34

The fix is to guard the transform logic on onReplace and don't attempt transforms. The inputRule function in the same file already guards on onReplace when handling the prefix transforms.

This bug was reported in WP.com automated JS error reporting.

@jsnajdr
jsnajdr requested review from Mamaduka, aduth and ellatrix July 30, 2026 15:12
@jsnajdr jsnajdr self-assigned this Jul 30, 2026
@jsnajdr jsnajdr added [Type] Bug An existing feature does not function as intended [Package] Block editor /packages/block-editor labels Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Size Change: +9 B (0%)

Total Size: 7.76 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 428 kB +9 B (0%)

compressed-size-action

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense 👍 Though my static typing brain wonders what the expected shape of onReplace should be, and if it's reasonable to expect it should always be a function that locking blocks could pass as a noop rather than as undefined.

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @jsnajdr!

@Mamaduka

Copy link
Copy Markdown
Member

@aduth, the RichText relies on a similar if ( onReplace ) check in a couple of places, which probably would require larger refactoring than just swapping with noop.

P.S. I think we had similar conversation on another Jarda's PRs 😄

@jsnajdr

jsnajdr commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

what the expected shape of onReplace should be

By not passing onReplace we signal to RichText that this operation is not available, and that it shouldn't attempt it. If onReplace was noop, then RichText would think it did the --- to core/separator transform, but in fact it wouldn't happen.

@jsnajdr
jsnajdr merged commit d1182f6 into trunk Jul 30, 2026
57 checks passed
@jsnajdr
jsnajdr deleted the fix/rich-text-transform-onreplace branch July 30, 2026 19:11
@jsnajdr jsnajdr added this to the Gutenberg 23.7 milestone Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants