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

Warnings and invalid HTML generated from gutenberg_render_elements_support() for empty block #33401

Closed
bobbingwide opened this issue Jul 13, 2021 · 2 comments

Comments

@bobbingwide
Copy link
Contributor

bobbingwide commented Jul 13, 2021

Description

After updating to Gutenberg 11.0.0 I noticed a number of Warnings being produced.
I analysed the problem in bobbingwide/thisis#34
and eventually determined that the problem occurs when the block being rendered has produced no output
but has a style attribute for the link color.

  • For my block this happened because the user was not logged in.
  • For the scenario to reproduce the problem below it occurs because the block is not registered.
  • The filter function is still being run against blank output.
  • This causes the Warnings to be displayed and the invalid output is generated.

Step-by-step reproduction instructions

  1. Add a new post.
  2. Enter Code edit
  3. Paste this content.
<!-- wp:paragraph --><p>Apart from this paragraph the only content in the post is another block with a style attribute. The template only displays the post-content. What could possibly go wrong?</p><!-- /wp:paragraph -->
<!-- wp:reproduce/issue34 {"style":{"elements":{"link":{"color":{"text":"var:preset|color|dark-grey"}}}}} /-->
  1. Save the post.
  2. View the post on the front end. See the unexpected output.
  3. Re edit the post
  4. Change style to smyle
  5. Save and view again
  6. The problem goes away.

Expected behaviour

The block should not appear on the front end.
There shouldn't be any attempt to generate a <style> tag.

Actual behaviour

Warning messages and invalid HTML generated

Warning: Undefined array key 0 in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 51

Warning: Trying to access array offset on value of type null in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 51

Warning: Undefined array key 0 in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 63

Warning: Trying to access array offset on value of type null in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 63

Apart from this paragraph the only content in the post is another block with a style attribute. The template only displays the post-content. What could possibly go wrong?

class=”wp-elements-60edf9307a0c3″

Screenshots or screen recording (optional)

This is what I got:

image

This is what @annezazu got
Screen Shot 2021-07-13 at 2 04 49 PM

Code snippet (optional)

Proposed fix:
Return early when the block content is empty

function gutenberg_render_elements_support( $block_content, $block )
{
    if ( empty( $block_content ) ) {
        return $block_content;
    }

WordPress information

  • WordPress version: 5.7.2 | 5.8-RC2
  • Gutenberg version: 11.0.0
  • Are all plugins except Gutenberg deactivated? No ( @bobbingwide )
  • Are you using a default theme (e.g. Twenty Twenty-One)? No ( @bobbingwide )

Device information

For @bobbingwide

  • Device: Desktop
  • Operating system: Windows 10
  • Browser:
@annezazu annezazu added the Needs Technical Feedback Needs testing from a developer perspective. label Jul 13, 2021
@Mamaduka
Copy link
Member

Hi, @bobbingwide

I believe this was resolved via #35836.

@talldan talldan removed the Needs Technical Feedback Needs testing from a developer perspective. label Apr 17, 2023
@talldan
Copy link
Contributor

talldan commented Apr 17, 2023

Sounds like it is resolved, so I'll close this.

@talldan talldan closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants