gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Post Content block can be added infinitely in Template Editor

Open fwazeter opened this issue 5 years ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Have you tried deactivating all plugins except Gutenberg?

  • [X] I have tested with all plugins deactivated.

Have you tried replicating the bug using a default theme e.g. Twenty Twenty?

  • [X] I have tested with a default theme.

Description

Attempting to use a post-content block in the block editor returns an error message: block cannot be rendered inside itself. (which makes sense, although maybe this post-content block should be disabled in the block editor by default).

Likewise, adding a post-content block within a PHP block template (e.g. through a function that hooks into init and uses get_post_type_object(); ) will not render in the block editor.

###Only PHP block templates set (WP_Post_Type): A PHP block template set (with NO corresponding .html template) will render in the template editor and be editable, with what appears to be preset values in 'defaultBlockTemplate' from block_editor_settings_all for header values and an auto-generated post-content block wrapper.

However, if you add a core/post-content block to your PHP block template, it'll render in the template editor and doesn't appear to impact anything on the front end, although post-titles will be duplicated if you fail to remove one of the post-titles since defaultBlockTemplate will add a post title block.

###Only HTML templates set (e.g. block-templates/single.html) .HTML template files do not automatically pass to the template editor -> you get defaultBlockTemplate settings. With No PHP Block Template: "Default" sets the defaultBlockTemplate file the system sets, rather than a specific HTML template (e.g. single.html), but even selecting a specific template in Gutenberg (e.g. Single Post w/single.html existing), it doesn't return anything other than the system defaults - rather than what's in single.html.

###PHP Block Template Set + Single.html exists Block editor renders the PHP block template and the PHP Block template is used wrapped inside the rest of the 'defaultBlockTemplate' set by the system. However, front end render will duplicate post-content if you set a post-content block in the html template.

###Within Template Editor, with PHP Block Template Set: You can add Post content blocks infinitely, duplicating the PHP Block template infinitely. This won't reflect in the block editor, but in the front end, it'll show and in the template editor it'll show.

###No PHP Block Template Set & Template Editor: You can infinitely add post-content blocks, but they are not immediately obvious unless you're looking at the list view (practically invisible). Likewise, these won't show in the Block Editor but will show on the front end.

###Override defaultBlockTemplate with your own setting via block_editor_settings_all: Probably best use case here is linking it up with your single.html, etc files. In this case, with no PHP block template set, it'll auto default to whatever you set in your e.g. single.html.

Again, can infinitely add post-content blocks within Template Editor.

###defaultBlockTemplate set + PHP block template set

PHP block template content auto added to 'post-content' block if you have it set in your defaultBlockTemplate. Seems logical. But, if you add more post-content blocks - repeats PHP block template code.

Step-by-step reproduction instructions

  1. Add New Post
  2. In Block Editor - try to add post-content block. Does not allow / error.
  3. Add New Template (settings panel - template - add new / edit).
  4. Add post-content block: can add infinitely.
  5. Go back to Block Editor - does not show this in block editor
  6. View post on front end or in template editor - shows duplicated content.

Expected Behavior

There should be a check that disallows more than 1 post-content block in a single page template. Maybe this is allowed for archive blocks?

Current Behavior

Infinite addition of post content! You can even nest post-content blocks within post-content blocks.

Screenshots or screen recording (optional)

No response

Code snippet (optional)

No response

WordPress Information

5.8

Gutenberg Information

Same behavior with Gutenberg 11.2.1 or with Gutenberg disabled.

What browsers are you seeing the problem on?

Firefox, Chrome

Device Information

Desktop

Operating System Information

Windows 10

fwazeter avatar Aug 11 '21 07:08 fwazeter

Hi there!

I tried adding a post-content block inside the template editor, the first one works but if I try to add a second one inside I get the error message. So it seems everything is working as intended for me.

youknowriad avatar Aug 11 '21 10:08 youknowriad

Hi there!

I tried adding a post-content block inside the template editor, the first one works but if I try to add a second one inside I get the error message. So it seems everything is working as intended for me.

That is utterly fascinating. I mean, that totally makes sense as the standard behavior.

Let me dig into this a little more on reproducing what's going on.

fwazeter avatar Aug 11 '21 10:08 fwazeter

@youknowriad

Here's the duplication on WP 5.8, Gutenberg 11.2.1 & TT1 blocks theme. (local server config: Nginx, PHP 7.4.1, MariaDB 10.4.10)

Edit to add: this same behavior happens in my own themes and a few other themes I tested, but used TT1 blocks for standardization in example.

https://user-images.githubusercontent.com/38684085/129013160-4fa1a3b9-a350-4a80-affc-87e372fd06df.mp4

fwazeter avatar Aug 11 '21 10:08 fwazeter

@fwazeter I understand better, thanks for the screenshot. That's actually not a bug but it's intended. The same way you can show the post title multiple times (imagine, one in the header, one in the footer), you're able to show post content in any place you want, as much as you want. What we prevent is recursively: "showing post content inside post content". I agree that the use-case for this as pretty small though.

youknowriad avatar Aug 11 '21 10:08 youknowriad

@youknowriad

I understand better, thanks for the screenshot. That's actually not a bug but it's intended. The same way you can show the post title multiple times (imagine, one in the header, one in the footer), you're able to show post content in any place you want, as much as you want. What we prevent is recursively: "showing post content inside post content". I agree that the use-case for this as pretty small though.

That adds some clarification, and really, in an existing theme absolutely nothing stops you from adding the_content() as much as you want, and functionality should be as flexible as is reasonably possible in core. Although, now I'm trying to think of a use case where it makes sense...maybe if someone is using a CPT for a content feature, like an FAQ or quote or something (although, this should largely go away with reusable blocks)?

In this instance, my observation would be that unless you're looking at list view, it's very difficult to see duplicate post content areas in the editor itself while the content is mostly empty. Though, I suppose that in this case, with cause for concern in a theme, it's just up to the theme author to extend the post-content template editor style with an outline or something. Users are pretty good at breaking things!

fwazeter avatar Aug 11 '21 11:08 fwazeter

Exactly, there might be some iterations to be done on some placeholder state or something for empty post content to make it clearer.

Thanks for your feedback.

youknowriad avatar Aug 11 '21 12:08 youknowriad