Opened 4 weeks ago
Closed 3 weeks ago
#63287 closed defect (bug) (fixed)
Unexpected output from apply_block_hooks_to_content_from_post_object
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8.1 | Priority: | normal |
Severity: | normal | Version: | 6.8 |
Component: | Editor | Keywords: | has-patch has-unit-tests fixed-major |
Focuses: | Cc: |
Description
When there are blocks hooked into 'core/post-content' => 'after'
, it creates unbalanced tags for remove_serialized_parent_block()
in apply_block_hooks_to_content_from_post_object()
:
<!-- wp:post-content --><!-- wp:heading {"level":1} --><h1>Hello World!</h1><!-- /wp:heading --><!-- /wp:post-content --><!-- wp:tests/hooked-block /-->
The result I'm seeing is the hooked block being removed and leaving the closing wp:post-content
tag:
<!-- wp:heading {"level":1} --><h1>Hello World!</h1><!-- /wp:heading --><!-- /wp:post-content -->
I'll attach a diff with failing tests to work against.
Attachments (1)
Change History (18)
This ticket was mentioned in PR #8695 on WordPress/wordpress-develop by @jorbin.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
This applies https://core.trac.wordpress.org/attachment/ticket/63287/post-content-after.diff in order to see the test results
#2
@
4 weeks ago
- Component changed from General to Editor
- Keywords has-patch has-unit-tests removed
Welcome back to trac @obenland!
I moved the patch to GH so we can all see the results of the automated tests.
#3
@
4 weeks ago
This also happens on non-block themes as well.
At the end of every post is <!-- /wp:post-content -->
I'm using the classic editor with a theme which doesn't use blocks.
#5
@
4 weeks ago
Right. So the crux is that the block wrapper is needed temporarily to allow for first/last child insertion into the Post Content block, as it translates between the post's ignoredHookedBlocks
meta (i.e. reads from post meta and sets the corresponding block attribute on the wrapper block, and writes back to post meta based on the latter upon writing).
It's a different story for before/after insertion: If a block is inserted before or after the wrapper, it'll confuse remove_serialized_parent_block()
, as @obenland pointed out.
I'll need to give this a bit more thought to figure out the correct solution. My intuition says that before/after insertion should be handled one layer higher (e.g. by the template that includes the Post Content block). In particular, I don't think that a hooked block inserted before/after a Post Content block should be stored inside its corresponding post object content. (Instead, it should probably end up next to the Post Content block, inside the containing markup.)
There are however some subtleties that we'll need to think through. For one, it raises the question where to store ignoredHookedBlocks
: Continue to use the post meta, or use the containing markup's post content block delimiter?
It will probably also mean that we'll lose the ability to insert before or after post content in a non-block theme, but that's probably okay (as we wouldn't be dealing with a Post Content block strictly speaking, so there's no anchor block before or after which we could insert our hooked block).
#6
@
4 weeks ago
- Milestone changed from Awaiting Review to 6.8.1
This might be pesky enough of an issue to warrant a fix in 6.8.1.
This ticket was mentioned in PR #8700 on WordPress/wordpress-develop by @Bernhard Reiter.
4 weeks ago
#7
- Keywords has-patch has-unit-tests added
WIP.
Needs additional test coverage:
- Hooked block inserted before/after Post Content block via
hooked_block_types
filter. - Hooked block inserted in before/after position _inside_ of Post Content block.
- Hooked block inserted before/after Post Content block contained in other context (e.g. inside a template).
Props @obenland @aaronjorbin @gziolo.
Trac ticket: https://core.trac.wordpress.org/ticket/63287
@Bernhard Reiter commented on PR #8695:
4 weeks ago
#8
Thank you @aaronjorbin and @obenland!
I've filed https://github.com/WordPress/wordpress-develop/pull/8700 to work on a fix.
@Bernhard Reiter commented on PR #8700:
4 weeks ago
#10
We should probably check what happens if the user modifies a template in the Site Editor that contains a Post Content block that has a block hooked before
or after
it.
4 weeks ago
#11
There are some reported coding style issues. Otherwise, all tests pass including newly added coverage for the advanced use case of using hooked_block_types
filter. Nice work!
#13
@
4 weeks ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening to seek a second Core Committer's approval for backporting to the 6.8 branch.
Diff to make tests fail