-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix dynamic blocks not rendering in the frontend #11050
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with Yoast, publishing a post with a reusable block that has an embedded tweet, to make sure that everything gets rendered. 🚢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The fix is working for me as well.
Wondering if we can add a test for this so it doesn't happen again?
If Travis is unhappy about coding styles, see #11051. |
@ocean90 I'm working on a test now |
@@ -312,7 +312,7 @@ function strip_dynamic_blocks_add_filter( $text ) { | |||
* @return string | |||
*/ | |||
function strip_dynamic_blocks_remove_filter( $text ) { | |||
remove_filter( 'the_content', 'strip_dynamic_blocks', 8 ); | |||
remove_filter( 'the_content', 'strip_dynamic_blocks', 6 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a constant to share that 6
between the _add_
and _remove_
pair?
The whole system for managing filter priority is fragile. :( Adding hooks in sequence would help (see example from core) but it doesn't work once we need to register temporary filters, such as the ones for excerpts. There aren't as many filters as in the past now, but would it make sense to assign priorities in a central map? $the_content_priority_strip_dynamic_blocks = 6;
$the_content_priority_do_blocks = 7;
$the_content_priority_gutenberg_wpautop = 8; // (do we still need `8`?) |
I ask because, in the 5.0 branch, no priority is assigned. This discrepancy worries me. /cc @pento |
@@ -35,4 +35,27 @@ describe( 'Meta boxes', () => { | |||
page.keyboard.up( 'Meta' ), | |||
] ); | |||
} ); | |||
|
|||
it( 'Should render dynamic blocks when the meta box uses the excerpt for front end rendering', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ Thanks for the test @notnownikki
https://wordpress.slack.com/archives/C02QB2JS7/p1540470819000100 This is probably related to the "autop" hook right? |
lib/blocks.php
Outdated
@@ -292,7 +295,7 @@ function strip_dynamic_blocks( $content ) { | |||
* @return string | |||
*/ | |||
function strip_dynamic_blocks_add_filter( $text ) { | |||
add_filter( 'the_content', 'strip_dynamic_blocks', 6 ); // Before do_blocks(). | |||
add_filter( 'the_content', 'strip_dynamic_blocks', $the_content_priority_strip_dynamic_blocks ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youknowriad for some reason I'm getting Undefined variable: the_content_priority_strip_dynamic_blocks
here.
Scoping issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, too much JS in my head. it should be fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're global
-ing already here + lengthy-named tracker variables across 2 files, is there some decent global class property available instead?
GutenbergVariables::$the_content_priority['strip_dynamic_block'] = 6
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're removing all gutenberg
from variable names (that will make it into Core). I don't have strong opinion personally on how to set these variables. I assume this will be different in Core and this code will be removed from the plugin once 5.0 is released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the wild, I'm seeing plugins that need to do special content processing, currently have to hardcode things like remove_filter the_content gutenberg_wpautop 8
, which means they instantly break when a release comes along that changes priorities.
Which is why some kind of a "well-known things" registry to pull from, would be much nicer for everybody.
But I understand this is a massive undertaking and can't be addressed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lkraav fair point and I'd suggest opening a trac issue for it as, this code is already merged there for 5.0 beta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I restored the hard-coded priorities for now. The variables were messing with the php unit tests. Any refactoring should happen separately.
Noting that this problem was reported to Yoast at Yoast/wordpress-seo#11402 and I commented to note that this PR will fix the problem: Yoast/wordpress-seo#11402 (comment) |
I added an e2e test to catch autop issues in the future. |
This issue referenced in t45172. |
80014f4
to
60e22bf
Compare
@youknowriad thanks. Are you planning a hotfix 4.1.1 here, or? |
@lkraav: yes |
* Fix dynamic blocks not rendering in the frontend * Use variables for hook priorities * Test that dynamic blocks are rendered when meta boxes use the excerpt * Fix autop hook order * Fix linting * Fix scoping issues * Add an e2e test for the autop issue * copy/paste issues * Trying to fix travis * Trim content to avoid small differences between themes
…rnmobile/merge-blocks-on-backspace * 'master' of https://github.com/WordPress/gutenberg: Do not add isDirty prop to DOM (#11093) Format API (#10209) Remove 4.2 deprecated features (#10952) Update `@wordpress/hooks` README to include namespace mention (#11061) Feature: save lock control via actions (#10649) Fix usage of `preg_quote()` (#10998) Update plugin version to 4.1.1 (#11078) Improve preloading request code (#11007) Fix dynamic blocks not rendering in the frontend (#11050) Media & Text: Fixing vertical alignment of the image (#11025) Date: Mark getSettings as experimental (#10636) Improve handling of centered 1-col galleries with small images (#11040) Use better help text for ALT text input; fixes #8391. (#11052) # Conflicts: # packages/editor/src/components/rich-text/index.native.js
Regression in 4.1 when you have dynamic blocks in your post and a meta box (like yoast). The dynamic blocks get stripped from the frontend.
In this PR https://github.com/WordPress/gutenberg/pull/10035/files#r228107590 we changed the priority of the different
the_content
hooks but we forgot to update the hook removal properly?Testing instructions
Related #8984