Skip to content

Inserter: Fix error being thrown for spoken message when inserting default/direct block#79004

Open
talldan wants to merge 3 commits into
trunkfrom
fix/inserter-errors-thrown
Open

Inserter: Fix error being thrown for spoken message when inserting default/direct block#79004
talldan wants to merge 3 commits into
trunkfrom
fix/inserter-errors-thrown

Conversation

@talldan
Copy link
Copy Markdown
Contributor

@talldan talldan commented Jun 8, 2026

What?

Currently the inserter can thrown an error on the navigation block.

Why?

#77877 seems to have unearthed a bug that was present long before that.

Before #77877, allowedBlockType could unusually be set to false, attempting to access allowedBlockType.title would be ok, but the title would be undefined, so users of assistive technologies would hear something like "undefined block added".

After #77877, allowedBlockType can be set to null, attempting to access allowedBlockType.title throws an error. I think the upstream code is better in using more expected types, attempting to access title throws.

How?

The new fix uses getBlockLabel to determine the label of the inserted block, which should be better. To take variations into account, the code also has to replicate what useBlockDisplayTitle does, using getActiveBlockVariation to fall back to the correct variation name.

Testing Instructions

The block I reproduced this on is navigation (inserting a navigation link when clicking the appender). You can't really hear the spoken message using voiceover because there are lots of other announcements at the same time. But I used a breakpoint in the browser dev tools to determine that the message is now "Page link block added".

  1. Add a navigation block
  2. Stick a breakpoint on the speak( message ) line

In this PR: message is "Page link block added".
In trunk: the code throws an error.

Use of AI Tools

OpenCode / Codex

@talldan talldan requested a review from Mamaduka June 8, 2026 06:34
@talldan talldan self-assigned this Jun 8, 2026
@talldan talldan requested a review from ellatrix as a code owner June 8, 2026 06:34
@talldan talldan added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Feature] Inserter The main way to insert blocks using the + button in the editing interface labels Jun 8, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jun 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2026

Size Change: +129 B (0%)

Total Size: 8.44 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 380 kB +129 B (+0.03%)

compressed-size-action

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2026

Flaky tests detected in 333610b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27120283056
📝 Reported issues:

const defaultBlockType = directInsertBlock
? getBlockType( directInsertBlock.name )
: null;
const _blockTypeToInsert = _blockToInsert
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.

Should we move all this logic inside insertOnlyAllowedBlock (with the registry) and calculate on demand?

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2026

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: talldan <talldanwp@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [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.

2 participants