Skip to content

Fix: Shortcode: The block switcher offers Gallery for [gallery] without ids, and choosing it throws an error - #87063

Merged
hbhalodia merged 4 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-87062
Nov 19, 2026
Merged

hbhalodia merged 4 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-87062

Conversation

@hbhalodia

Copy link
Copy Markdown
Contributor

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] without ids, 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 when ids is set, so for [gallery] the switcher listed Gallery while switchToBlockType() returned null. Choosing it threw TypeError: 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 without ids it shows the post's attached images.

How?

isSingleShortcode() now also runs the target transform's isMatch against the matched shortcode's attributes, as the paste path already does in shortcode-converter.ts.

  • In core, only Gallery's shortcode transform has an isMatch, so Video, Audio, Embed and Image ([caption]) are offered as before.
  • A plugin block whose shortcode transform has an isMatch gets the same check.
  • An e2e test checks that [gallery] without ids doesn't offer Gallery.

Testing Instructions

  1. In a new post, insert a Shortcode block and type [gallery].
  2. Open the block switcher in the block toolbar. Transform to lists only Columns, Details and Group, and nothing is logged in the console.
  3. Change the text to [gallery include="X,Y"]. The result is the same.
  4. Change the text to [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.
  5. Run the e2e test: npm run test:e2e -- test/e2e/specs/editor/blocks/shortcode.spec.js

Testing Instructions for Keyboard

  • None

Screenshots or screencast

Before After
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.

@hbhalodia
hbhalodia requested a balanced review from Copilot November 19, 2026 05:57
@hbhalodia hbhalodia self-assigned this Nov 19, 2026
@hbhalodia hbhalodia added [Type] Bug An existing feature does not function as intended [Package] Block library /packages/block-library [Block] Gallery Affects the Gallery Block - used to display groups of images [Block] Shortcode Affects the Shortcode Block labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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: hbhalodia <hbhalodia@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.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@hbhalodia
hbhalodia marked this pull request as ready for review November 19, 2026 05:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 isMatch against shortcode attributes, consistent with paste handling.
  • Adds an end-to-end regression test for [gallery] without ids.
  • 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

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

Good catch, @hbhalodia!

@hbhalodia
hbhalodia enabled auto-merge (squash) November 19, 2026 06:12
@hbhalodia
hbhalodia merged commit 14a3ffa into WordPress:trunk Nov 19, 2026
83 of 84 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Gallery Affects the Gallery Block - used to display groups of images [Block] Shortcode Affects the Shortcode Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shortcode: The block switcher offers Gallery for [gallery] without ids, and choosing it throws an error

3 participants