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

Site Editor: Remove call to wpautop that unintentionally alters block markup in template parts #30552

Conversation

andrewserong
Copy link
Contributor

Description

This change is very similar to an older draft PR (#20452 kudos @johnstonphilip) and follows on from discussion in #20343 (comment) where it was proposed to remove the call to wpautop when rendering template parts.

It turns out, while working on a plugin that server renders a block (in this case it was the Jetpack Rating Star block), I noticed that when the block was rendered within a template part, the markup was incorrect and broke the styling for the block, however when the block was rendered within normal post content, the markup was correct.

In core, when do_blocks is called, it checks to see whether or not it's running within the_content filter, and if so, it disables calling wpautop for that run of the filter.

However, in render_block_core_template_part we call do_blocks directly instead of within the context of the_content, so the code to disable wpautop doesn't fire (and it wouldn't do anything, anyway).

Since the expected behaviour of calling do_blocks with block content is for wpautop to be disabled, let's remove the call to it as proposed in #20343 (comment) and #20452

How has this been tested?

Manually in a local development environment running the Gutenberg plugin and the Jetpack plugin, using the Star Rating block (a server-rendered block that expects not to have <p> tags injected into it).

While I tested this with the Jetpack plugin, I believe other plugins will run into a similar issue with server rendered blocks in template parts, so thought it better to fix this in Gutenberg rather than add a workaround in the plugin.

Screenshots

Editor view

This is the editor view of inserting the Jetpack Star Rating block into the Footer template part:

image

Front-end view (without this change applied)

image

Front-end view (with this change applied)

image

Types of changes

Bug fix for blocks rendered within template parts.

Checklist:

  • My code is tested. (manually tested)
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers. N/A
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@glendaviesnz
Copy link
Contributor

glendaviesnz commented Apr 8, 2021

👍 Works as advertised for me, but I don't know enough about the implications of removing this call to give it a ✅

@johnstonphilip do you have any thoughts on this?

@glendaviesnz glendaviesnz added [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended labels Apr 8, 2021
@andrewserong
Copy link
Contributor Author

Just adding that this will resolve issues for a number of other Jetpack blocks, including the Contact Form and Podcast Player blocks.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanation makes sense. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants