-
Notifications
You must be signed in to change notification settings - Fork 9
Correctly parse synced patterns with nested blocks #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great fix! I like that the core/block
addition is actually smaller now, and we've doubled the size of the tests on synced patterns. The new tests cover a lot more.
It'd be great to have @toshotosho verify on real data first per the bug in #86, but I'm happy to merge when verified.
public function test_synced_pattern_with_override_in_nested_content() { | ||
$synced_pattern_content = ' | ||
<!-- wp:group --> | ||
<div class=k"wp-block-group"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor note, there's 3 k"
s scattered in here that appear to be an accident, unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 5dbe308
#vimfail
'inner_blocks' => [], | ||
'locked' => false, | ||
]; | ||
if ( ! $post instanceof \WP_Post ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extreme nit - can we use use WP_Block;
up top and this for consistency?
if ( ! $post instanceof \WP_Post ) { | |
if ( ! $post instanceof WP_Post ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Fixed in fc24575
Thanks guys! I just deployed the fix and it solves our issue without breaking anything else, so great work! |
Description
Fixes #86.
Our current solution for extracting and parsing blocks from synced patterns is a bit too experimental. It hooks into the render cycle and attempts to detect when the block being rendered has a synced pattern parent block. It does this via a somewhat fragile inspection of
WP_Block_Supports
.The issue with that approach is that it can't tell when the synced pattern is a direct parent block vs. an ancestor block, so it ends up duplicating blocks in nested trees. There's no way to make this determination reliably, so we need to abandon that approach.
Instead of hooking into the existing render cycle, we can just render synced patterns manually. This carries some of its own fragility, because we need to duplicate some code from Core to support synced pattern overrides. But it's an overall improvement and the duplicated code is just a few lines.
It does require making
ContentParser#render_parsed_block
a public method, which was the path I found that required the least refactoring.@toshotosho Thanks for the failing test case. Can you check out this branch and make sure it resolves the issue for you? Feel free to contribute additional test cases.