Opened 21 months ago
Closed 15 months ago
#58027 closed defect (bug) (fixed)
Post Content / Post Featured Image blocks break content if added before the loop
Reported by: | edge22 | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Editor | Keywords: | has-testing-info has-patch gutenberg-merge |
Focuses: | Cc: |
Description (last modified by )
Since 6.2, any "classic" theme that hooks the core "Post Featured Image" block before the loop causes the content within the loop to disappear.
To replicate:
- Use a "classic" theme like Twenty Twenty-One.
- Hook the Post Featured Image block into the theme before the loop begins:
<?php add_action( 'wp_body_open', function() { $block_content = '<!-- wp:post-featured-image /-->'; $block = parse_blocks($block_content)[0]; echo render_block($block); } );
- View a single post.
The content will be gone.
This is an issue if any theme is allowing users to insert this block as a page hero before the loop begins.
This is the PR that introduced the error: https://github.com/WordPress/gutenberg/pull/45534
Change History (18)
#1
@
21 months ago
- Summary changed from Post Featured Image block breaks content if added before the loop to Post Content / Post Featured Image blocks break content if added before the loop
- Version changed from 6.2 to 5.8
#2
@
21 months ago
That's a tough one since what takes effect here is the combination of post content and post featured image, which also calls the_post
: https://github.com/WordPress/gutenberg/pull/45534
The reason is the same for both, as some places in code check if they are in the loop and this is bad to start with. Ideally templates/blocks shouldn't rely on the loop(that goes for post content) and maybe there could be another way to handle lazy loading of images?
I'm not sure how we could find plugins or blocks that rely on the loop and start a deprecation process.. Normally using block context could make the trick, but I'm not sure of the nuances of every use case. Recently there was a related discussion here: https://github.com/woocommerce/woocommerce-blocks/discussions/8792.
Backwards compatibility is tough.
This ticket was mentioned in Slack in #core-test by ironprogrammer. View the logs.
21 months ago
#4
@
21 months ago
- Description modified (diff)
- Keywords has-testing-info added
Updated "classic" theme referenced in reproduction step 1 to TT1 (TT2 is a block theme).
#5
@
21 months ago
Reproduction Report
I was also able to reproduce this in TT1 and TT.
Environment
- Hardware: MacBook Pro Apple M1 Pro
- OS: macOS 12.6.3
- Browser: Safari 16.3
- Server: nginx/1.23.4
- PHP: 7.4.33
- WordPress: 6.2
- Theme: twentytwentyone, twentytwenty
- Active Plugins:
- body-open (custom mu-plugin that hooks
wp_body_open
as indicated in repro steps)
- body-open (custom mu-plugin that hooks
Actual Results
- ✅ Post content on single post page is not output.
Additional Information
- As noted in comment:1, I could also repro this issue using a
post-content
block (tested in WP 6.1.1).
This ticket was mentioned in Slack in #core-test by oglekler. View the logs.
20 months ago
#8
@
20 months ago
The task was linked with https://core.trac.wordpress.org/ticket/58111#comment:4 for future investigation. Looks like they are duplicated.
#9
@
20 months ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 6.3
- Owner set to flixos90
- Status changed from new to assigned
I have identified a more appropriate solution for the underlying problem here, which basically was a workaround for a problem identified in #58154.
In order to fix the problem, we'll need to:
- Merge this Gutenberg PR https://github.com/WordPress/gutenberg/pull/49904
- Port it over to WordPress core
- Merge this core PR https://github.com/WordPress/wordpress-develop/pull/4341
@hellofromTonya Flagging this ticket as it will require a Gutenberg fix to be ported over to WordPress core in order to get fixed.
#11
@
18 months ago
- Milestone changed from 6.3 to 6.4
Unfortunately there is no consensus on this yet, and as the Gutenberg PR https://github.com/WordPress/gutenberg/pull/49904 hasn't been merged, this has to be punted.
#12
@
17 months ago
- Keywords gutenberg-merge added
As this ticket is dependent upon code from Gutenberg being merged into Core, adding the gutenberg-merge
keyword for tracking purposes.
#13
@
16 months ago
After some additional digging, which led to discovery of a more severe underlying problem (see #59225), the Gutenberg PR https://github.com/WordPress/gutenberg/pull/49904 has been updated with a detailed description. Once that is merged and backported to WP core, this bug here will be fixed.
This ticket was mentioned in Slack in #core-performance by flixos90. View the logs.
16 months ago
This ticket was mentioned in Slack in #core by joemcgill. View the logs.
16 months ago
#16
@
16 months ago
For reference, the bug reported in https://github.com/WordPress/gutenberg/issues/53593 is happening for the same reason as this one. cc @gziolo
On another note, the Gutenberg PR https://github.com/WordPress/gutenberg/pull/49904 has been merged. Next steps are:
- Commit the PR for #58154
- Port the above Gutenberg update into core
@edge22 I can reproduce this issue. I am curious however, how did you ran into it? My first hunch would be to consider this an edge-case, since why would you use a block intended for FSE / block themes in a classic theme? I would like to understand in which legitimate use-case would be affected by this bug.
I also would like to add that this bug is not actually new. While the logic was added to the
post-featured-image
block in 6.2, it was directly taken over from the same code being in thepost-content
block. If you put the same code from your snippet but with thepost-content
block, you'll see the same problem occur. While I would love to understand better where this realistically is a problem, I certainly agree that that logic feels clunky, and I am not sure why it's there.The logic (i.e. also the bug) has been in that block since it was originally added in WordPress 5.8 (introduced as part of [50929] and [51344]). Digging further, it looks like the original logic was introduced in https://github.com/WordPress/gutenberg/pull/30405. Acknowledging that this was added almost 2 years ago, @aristath @ntsekouras do you have any memory on why enforcing a loop was added in the
core/post-content
block? Shouldn't we rather make sure, outside of that block, that it is used within a loop?