-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c45eaa8
Fix dynamic blocks not rendering in the frontend
youknowriad f1fb1eb
Use variables for hook priorities
youknowriad fb382f8
Test that dynamic blocks are rendered when meta boxes use the excerpt
notnownikki b605ed8
Fix autop hook order
youknowriad 169f5f4
Fix linting
youknowriad 544c337
Fix scoping issues
youknowriad 60e22bf
Add an e2e test for the autop issue
youknowriad 70be656
copy/paste issues
youknowriad c9899c3
Trying to fix travis
youknowriad 8152dca
Trim content to avoid small differences between themes
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/e2e/specs/__snapshots__/compatibility-classic-editor.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Compatibility with Classic Editor Should not apply autop when rendering blocks 1`] = ` | ||
" | ||
|
||
<a> | ||
Random Link | ||
</a> | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { newPost, insertBlock, publishPost } from '../support/utils'; | ||
|
||
describe( 'Compatibility with Classic Editor', () => { | ||
beforeEach( async () => { | ||
await newPost(); | ||
} ); | ||
|
||
it( 'Should not apply autop when rendering blocks', async () => { | ||
// Save should not be an option for new empty post. | ||
expect( await page.$( '.editor-post-save-draft' ) ).toBe( null ); | ||
|
||
// Add title to enable valid non-empty post save. | ||
await insertBlock( 'Custom HTML' ); | ||
await page.keyboard.type( '<a>' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( 'Random Link' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( '</a>' ); | ||
await publishPost(); | ||
|
||
// View the post. | ||
const viewPostLinks = await page.$x( "//a[contains(text(), 'View Post')]" ); | ||
await viewPostLinks[ 0 ].click(); | ||
await page.waitForNavigation(); | ||
|
||
// Check the the dynamic block appears. | ||
const content = await page.$eval( '.entry-content', ( element ) => element.innerHTML ); | ||
expect( content ).toMatchSnapshot(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { newPost } from '../support/utils'; | ||
import { newPost, insertBlock, publishPost } from '../support/utils'; | ||
import { activatePlugin, deactivatePlugin } from '../support/plugins'; | ||
|
||
describe( 'Meta boxes', () => { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ Thanks for the test @notnownikki |
||
// Publish a post so there's something for the latest posts dynamic block to render. | ||
await newPost(); | ||
await page.type( '.editor-post-title__input', 'A published post' ); | ||
await insertBlock( 'Paragraph' ); | ||
await page.keyboard.type( 'Hello there!' ); | ||
await publishPost(); | ||
|
||
// Publish a post with the latest posts dynamic block. | ||
await newPost(); | ||
await page.type( '.editor-post-title__input', 'Dynamic block test' ); | ||
await insertBlock( 'Latest Posts' ); | ||
await publishPost(); | ||
|
||
// View the post. | ||
const viewPostLinks = await page.$x( "//a[contains(text(), 'View Post')]" ); | ||
await viewPostLinks[ 0 ].click(); | ||
await page.waitForNavigation(); | ||
|
||
// Check the the dynamic block appears. | ||
await page.waitForSelector( '.wp-block-latest-posts' ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.