Skip to content
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

Infinite recursion trying to edit a wp_template with revisions containing wp:post-content blocks #26593

Closed
bobbingwide opened this issue Oct 30, 2020 · 11 comments · Fixed by #31455
Assignees
Labels
[Block] Post Content Affects the Post Content Block [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@bobbingwide
Copy link
Contributor

Describe the bug
I'm learning how to develop a Full Site Editing theme.
Sometimes I use the Site Editor (beta) and other times Appearance > Templates or Appearance > Template Parts.

Having created a template-part called post-content I encountered problems when I attempting to edit some of the Templates ( wp_template ). The editor never loaded. It either timed out or produced a Fatal error - memory exhausted.

I tracked the problem down to a never ending recursion involving the_content and pre_render_block, while running WP_Rest_Revisions_Controller->prepare_item_for_response().

The problem occurs when the wp:post-content block is being processed.

Between them the block rendering in gutenberg_render_block_with_assigned_block_context() and the_content filtering in
gutenberg_render_block_core_post_content() produces a never ending recursive loop which isn't shortcircuited by the current test on the $block->context['postId'] in gutenberg_render_block_core_post_content().

Example:
This is the content of the revision postId = 715 which is an autosaved revision of the single wp_template 694.

<!-- wp:template-part {"postId":665,"slug":"header-2-columns","theme":""} /-->

<!-- wp:post-title /-->

<!-- wp:post-content /-->

<!-- wp:template-part {"postId":548,"slug":"footer-part","theme":"fizzie"} /-->

To reproduce
Steps to reproduce the behavior:

  1. Using FSE create a template which contains wp:post-content ( e.g. single ).
  2. Edit it to create a revision (*)
  3. Save and return to the dashboard.
  4. Use Appearance > Templates.
  5. Use the Edit link to open the editor.
  6. Wait until it goes wrong.

(*) I believe the problem may occur with both autosaved revisions and user saved revisions.

Expected behavior
The Editor should display the 'single' Template, with the template parts rendered.
The post content block should say "This is a placeholder for post content."

Screenshots
Here I get the Fatal error due to the logic in my tracing plugin. It happens a lot earlier than the time out.

image

Editor version (please complete the following information):

  • WordPress version: [e.g: 5.3.2] 5.6-beta1
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? [e.g: "gutenberg plugin", "default"] Gutenber 9.2.2 or latest Gutenberg source with FSE enabled.

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] latest

Additional context

if ( 'revision' === $block->context['postType'] ) {
		return '';
}
@youknowriad youknowriad added [Feature] Full Site Editing Needs Testing Needs further testing to be confirmed. labels Nov 2, 2020
@bobbingwide
Copy link
Contributor Author

Here's a screenshot of the problem being reproduced using the Twenty Twenty-One Blocks theme
in a WordPress Multi Site site called tt1. WordPress 5.6-beta3
The only active plugin was Gutenberg source.

image

Steps.

  1. Using Appearance > Templates, use Add New to create the single template
  2. Copy and paste the template from the .html file.
  3. Update
  4. Remove the post-excerpt and post-comments blocks
  5. Update again.
  6. Go to Appearance > Templates
  7. Select the 'single' post and choose Edit.
  8. See Fatal error.

Content after Step 2.

<!-- wp:template-part {"slug":"header","theme":"twentytwentyone-blocks","align":"full", "tagName":"header","className":"site-header"} /-->

<!-- wp:post-title {"level":1,"align":"wide"} /-->

<!-- wp:separator {"align":"wide","className":"is-style-twentytwentyone-separator-thick"} -->
<hr class="wp-block-separator alignwide is-style-twentytwentyone-separator-thick"/>
<!-- /wp:separator -->

<!-- wp:spacer {"height":70} -->
<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:post-content /-->
<!-- wp:post-excerpt /-->
<!-- wp:post-comments /-->

<!-- wp:template-part {"slug":"footer","theme":"twentytwentyone-blocks","align":"full","tagName":"footer","className":"site-footer"} /-->

After editing. Step 4.

<!-- wp:template-part {"slug":"header","theme":"twentytwentyone-blocks","tagName":"header","align":"full","className":"site-header"} /-->

<!-- wp:post-title {"level":1,"align":"wide"} /-->

<!-- wp:separator {"align":"wide","className":"is-style-twentytwentyone-separator-thick"} -->
<hr class="wp-block-separator alignwide is-style-twentytwentyone-separator-thick"/>
<!-- /wp:separator -->

<!-- wp:spacer {"height":70} -->
<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:post-content /-->

<!-- wp:template-part {"slug":"footer","theme":"twentytwentyone-blocks","tagName":"footer","align":"full","className":"site-footer"} /-->

@bobbingwide
Copy link
Contributor Author

I've retested this issue with the fixes for #26923 in PR #27012
In that solution there is no need for the new test

if ( 'revision' === $block->context['postType'] ) {
		return '';
}

@noisysocks
Copy link
Member

Hi @bobbingwide! I followed your reproduction steps but wasn't able to see any infinite recursion. Are you still seeing this? If so, maybe could you post a screen recording of you triggering the error?

@gziolo
Copy link
Member

gziolo commented Apr 13, 2021

It was fixed with #28456. I didn't reference this issue properly. I will close this one, but I'm happy to work on a follow-up if something related pops up. It's a complex issue 😄

@gziolo gziolo closed this as completed Apr 13, 2021
@bobbingwide
Copy link
Contributor Author

bobbingwide commented Apr 13, 2021

Hi @bobbingwide! I followed your reproduction steps but wasn't able to see any infinite recursion. Are you still seeing this? If so, maybe could you post a screen recording of you triggering the error?

Hi @noisysocks. The problem has now changed. It doesn't go recursive in the server but it does in the editor.
I'd raised this as a new issue against my experimental theme Fizzie but have just reproduced it using the Phoenix theme.

bobbingwide/fizzie#61

@gziolo gziolo reopened this Apr 13, 2021
@gziolo
Copy link
Member

gziolo commented Apr 13, 2021

Let's reopen as we don't have the Post Content block covered. I almost forgot about it. Thanks for bringing it up again @bobbingwide.

@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Priority] High Used to indicate top priority items that need quick attention [Block] Post Content Affects the Post Content Block and removed Needs Testing Needs further testing to be confirmed. labels Apr 13, 2021
@bobbingwide
Copy link
Contributor Author

Steps to reproduce in the newly re-opened issue.

  1. Use an FSE theme such as TT1 blocks v0.4.5
  2. Open Site Editor (beta).
  3. Select the Group containing Post content
  4. From the toolbar choose Options > Make template part
  5. Create a template part called single-content
  6. Return to the Dashboard ( Toggle navigation > Templates > Theme > Dashboard ) and confirm you want to leave.
  7. Choose Appearance > Template Parts
  8. Edit single-content

This is what I got this time.
Initially it was:
image

then I clicked on List view and this started flashing away

image

@bobbingwide
Copy link
Contributor Author

Another part of the screen to consider...
what are the breadcrumbs supposed to do when block nesting exceeds
the window width?

image

@gziolo
Copy link
Member

gziolo commented Apr 14, 2021

Yes, those impressive fractals are all coming from how the Post Content blocks work. Once it is fixed internally, it should disappar.

@bobbingwide
Copy link
Contributor Author

Any comment on my aside regarding the breadcrumbs? I haven't ever manually created that level of nesting nor used very long block names in a language other than English.

@gziolo
Copy link
Member

gziolo commented Apr 14, 2021

Any comment on my aside regarding the breadcrumbs? I haven't ever manually created that level of nesting nor used very long block names in a language other than English.

No clue, it's a separate issue though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Content Affects the Post Content Block [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
5 participants