Block Hooks: Try Streaming Parser #8006
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Longer-term experiment, based on #5753. Currently just copying over code from that PR. More to come 😬
With the introduction of
apply_block_hooks_to_content()
in WP 6.6, which in 6.7 became the main entry point for Block Hooks across the board — regardless of whether applied to templates, patterns, Navigation blocks, or Post Content, it has become easier to swap out the existing Block Hooks implementation (which requires parsing the block markup into a tree, which is then traversed and re-serialized) for a streaming parser.Block Hooks are fairly exhaustively covered by unit tests, but a large number of those tests covers lower-level functions that operate at block tree level. In order for this experiment to become viable, we will need to replace them with something that operates directly on block markup level -- see the below roadmap.
Roadmap:
inject_hooked_blocks_into_content
intoapply_block_hooks_to_content
(to replace the existing block tree traversal based implementation with it).apply_block_hooks_to_content
. Analyze what they're doing, and replace them with tests that coverapply_block_hooks_to_content
to ensure equivalent behavior.Trac ticket:
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.