Skip to content

Experiment: WP streaming block parser#2900

Draft
mardelnet wants to merge 1 commit intomainfrom
experimentation/streaming-block-parser
Draft

Experiment: WP streaming block parser#2900
mardelnet wants to merge 1 commit intomainfrom
experimentation/streaming-block-parser

Conversation

@mardelnet
Copy link
Contributor

Summary

This PR experiments with the new WP streaming block parser introduced with WordPress 6.9.

This block parser presents a streaming interface to walk through a document and analyze or modify the block structure. So far, the way of doing that was through the parse_blocks() function. Calling parse_blocks() converts the entire post into a large nested array of block information that contains two copies of every span of HTML from the input . All of this work can lead to some surprisingly heavy parsed documents. Further, because block structure is inherently nested, any code wanting to traverse all of the blocks in a document needs to create its own form of recursion to iterate through the output of parse_blocks(). The block parser was designed for cases where parse_blocks() would otherwise perform unnecessary work.

In this particular experiment, I use the block parser to replace the parse_blocks() function and a (somewhat complex) recursive function in its task of detecting a YouTube player on the current page.


Testing

  1. Embed a YouTube video on any page or post.
  2. Check that the /assets/build/lite-yt-embed.js file was enqueued.
  3. Remove the video.
  4. Now the JS file should not be enqueued.

- Experiment with the WP streaming block parser
@mardelnet mardelnet self-assigned this Feb 20, 2026
@mardelnet mardelnet added DO NOT MERGE PoC Pull requests that are defined as a proof of concept labels Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO NOT MERGE PoC Pull requests that are defined as a proof of concept

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant