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

Fix dynamic blocks not rendering in the frontend #11050

Merged
merged 10 commits into from
Oct 25, 2018

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Oct 25, 2018

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

  • Install Yoast
  • Add a dynamic block (latest posts)
  • The block should show up in the frontend
  • Would be good to check that the excerpts are still stripping the dynamic blocks.

Related #8984

@youknowriad youknowriad added [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release labels Oct 25, 2018
@youknowriad youknowriad self-assigned this Oct 25, 2018
@youknowriad youknowriad requested a review from a team October 25, 2018 10:08
Copy link
Member

@notnownikki notnownikki left a 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. 🚢

Copy link
Member

@ocean90 ocean90 left a 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?

@gziolo
Copy link
Member

gziolo commented Oct 25, 2018

If Travis is unhappy about coding styles, see #11051.

@notnownikki
Copy link
Member

@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 );
Copy link
Contributor

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?

@mcsf
Copy link
Contributor

mcsf commented Oct 25, 2018

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`?)

@youknowriad
Copy link
Contributor Author

@mcsf Sounds like a good idea to me.

Also ping @pento because this might have an impact on 5.0 as well

@youknowriad
Copy link
Contributor Author

$the_content_priority_gutenberg_wpautop = 8; // (do we still need 8?)

That's a good question, and if I were to guess, it needs to run before do_blocks as this was the case before #10035 (@aduth is this true?)

We might need an e2e test for it.

@mcsf
Copy link
Contributor

mcsf commented Oct 25, 2018

$the_content_priority_gutenberg_wpautop = 8; // (do we still need 8?)

That's a good question, and if I were to guess, it needs to run before do_blocks as this was the case before #10035 (@aduth is this true?)

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 () => {
Copy link
Contributor Author

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

@youknowriad
Copy link
Contributor Author

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 );
Copy link

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔

Copy link
Contributor Author

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.

Copy link

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.

Copy link
Contributor Author

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.

Copy link

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@designsimply
Copy link
Member

designsimply commented Oct 25, 2018

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)

@youknowriad
Copy link
Contributor Author

I added an e2e test to catch autop issues in the future.

@youknowriad youknowriad added this to the 4.1 - UI freeze milestone Oct 25, 2018
@mcsf
Copy link
Contributor

mcsf commented Oct 25, 2018

I ask because, in the 5.0 branch, no priority is assigned

This issue referenced in t45172.

@youknowriad youknowriad force-pushed the fix/dynamic-blocks-with-metaboxes branch from 80014f4 to 60e22bf Compare October 25, 2018 14:41
@youknowriad youknowriad merged commit 4317761 into master Oct 25, 2018
@youknowriad youknowriad deleted the fix/dynamic-blocks-with-metaboxes branch October 25, 2018 16:05
@lkraav
Copy link

lkraav commented Oct 25, 2018

@youknowriad thanks. Are you planning a hotfix 4.1.1 here, or?

@mcsf
Copy link
Contributor

mcsf commented Oct 25, 2018

@lkraav: yes

antpb pushed a commit to antpb/gutenberg that referenced this pull request Oct 26, 2018
* 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
daniloercoli added a commit that referenced this pull request Oct 26, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants