Skip to content

Block Parser: Fix implicit block closing error. - #13720

Open
dmsnell wants to merge 3 commits into
WordPress:trunkfrom
dmsnell:blocks/fix-parser-when-missing-closers
Open

dmsnell wants to merge 3 commits into
WordPress:trunkfrom
dmsnell:blocks/fix-parser-when-missing-closers

Conversation

@dmsnell

@dmsnell dmsnell commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: Core-66176

See WordPress/gutenberg#74427.
Dependent on #13695.

When reaching the end of a document during block parsing, and blocks
remain open, existing open blocks should implicitly close. Previously,
there was a mistake in the closing code which duplicated content in the
implicitly-closed blocks.

In this patch, the semantic actions of closing blocks is extracted for
easier identification of the logic, and the defect is resolved.

@github-actions

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dmsnell.

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

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

dmsnell added a commit to WordPress/gutenberg that referenced this pull request Sep 24, 2026
…4427)

Trac ticket: Core-66176
See WordPress/wordpress-develop#13720

There has been a known memory explosion for posts with deep stacks of
unclosed blocks. These posts experience exponential memory use and can
require gigabytes of memory to parse completely.

This was due to a mismatch in the spec and default parsers which led
to catastrophic string duplciation on account of how the default parser
closed out these blocks.

In this patch, the behavior is updated to implicitly close all open
blocks when the end of the document is reached. This remains divergent
from the spec parser, which treats a failure to find the closing
delimiters as one giant freeform block, but the behavior should be
better in general for truncated posts, given that it leaves intact as
many elements of the block structure as are viable.

Github-PR: 74427
Github-PR-URL: #74427
This patch unifies parsing between `WP_Block_Parser` and
`WP_Block_Processor`, which brings the additional benefit of the
optimizations in `WP_Block_Processor`.
This patch unifies parsing between `WP_Block_Parser` and
`WP_Block_Processor`, which brings the additional benefit of the
optimizations in `WP_Block_Processor`.
See WordPress/gutenberg#74427.

When reaching the end of a document during block parsing, and blocks
remain open, existing open blocks should implicitly close. Previously,
there was a mistake in the closing code which duplicated content in the
implicitly-closed blocks.

In this patch, the semantic actions of closing blocks is extracted for
easier identification of the logic, and the defect is resolved.
@dmsnell
dmsnell force-pushed the blocks/fix-parser-when-missing-closers branch from 26b34f0 to 236659f Compare September 29, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant