Repository navigation
Fix: Shortcode: The block switcher offers Gallery for [gallery] without ids, and choosing it throws an error - #87063
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the fix that respects target matching conditions when offering shortcode conversions.
No open issues 🎉
What changed in this PR
Fixes the Shortcode block switcher to respect each target transform’s matching conditions, preventing Gallery from being offered for [gallery] without ids.
Changes:
- Checks the target transform’s
isMatchagainst shortcode attributes, consistent with paste handling. - Adds an end-to-end regression test for
[gallery]withoutids. - Documents the fix in the block-library changelog.
| File | Description |
|---|---|
| test/e2e/specs/editor/blocks/shortcode.spec.js | Verifies that an unsupported Gallery conversion is not offered. |
| packages/block-library/src/shortcode/transforms.js | Applies target matching conditions before offering shortcode transforms. |
| packages/block-library/CHANGELOG.md | Records the block switcher fix. |
Review effort: Balanced
What?
Closes #87062
The block switcher now only offers to transform a Shortcode block into another block when the shortcode meets that block's own conditions. For
[gallery]withoutids, Gallery is no longer offered.Why?
Since #77944, the switcher lists a target block when the shortcode's tag matches, but it skipped the target transform's own
isMatch. Gallery's shortcode transform only matches whenidsis set, so for[gallery]the switcher listed Gallery whileswitchToBlockType()returnednull. Choosing it threwTypeError: Cannot read properties of null (reading 'name'), and the block stayed a Shortcode block. Pasting[gallery]already keeps it as a Shortcode block (#11551), because withoutidsit shows the post's attached images.How?
isSingleShortcode()now also runs the target transform'sisMatchagainst the matched shortcode's attributes, as the paste path already does inshortcode-converter.ts.isMatch, so Video, Audio, Embed and Image ([caption]) are offered as before.isMatchgets the same check.[gallery]withoutidsdoesn't offer Gallery.Testing Instructions
[gallery].[gallery include="X,Y"]. The result is the same.[gallery ids="X,Y"], using the IDs of two images in the Media Library. Gallery is listed, hovering it shows a preview, and clicking it converts the block.npm run test:e2e -- test/e2e/specs/editor/blocks/shortcode.spec.jsTesting Instructions for Keyboard
Screenshots or screencast
Screen.Recording.2026-11-19.at.11.10.00.AM.mov
Screen.Recording.2026-11-19.at.11.21.30.AM.mov
Use of AI Tools
Claude Code (Claude Opus 5.5) was used to trace the cause and draft the fix, the e2e test and this description. I reproduced the bug, reviewed all changes and ran the e2e test.