-
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
Merge Comments and Post Comments blocks #41807
Conversation
I thought the following code was working, but it turned out that I hadn't tested all the different possibilities. gutenberg/packages/block-library/src/comments/save.js Lines 9 to 19 in f35d33b
In line 15, |
$output = ob_get_clean(); | ||
|
||
wp_enqueue_script( 'comment-reply' ); | ||
|
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.
wp_reset_postdata(); |
Sorry to hear -- I remember that it was one of the major problems with #40522 that we never found a straight-forward and reliable way to infer if the block has existing children or not. I guess it's time we try a different strategy. At the time of conversion from
|
As discussed in Slack with @DAreRodz and @c4rl0sbr4v0, it might make sense to decouple the block merge from the ID change (to I think we can continue working on both of them independently; we'll just need to merge #40506 before this one (and then rebase this one to pick up the changed IDs). |
Another thing that @DAreRodz and I discussed on our video call earlier today is ensuring backwards compatibility. The question thus remains what happens if we have existing post content with those old blocks that haven't been edited.
|
variations: [ | ||
{ | ||
name: 'default', | ||
isDefault: true, | ||
innerBlocks: TEMPLATE, | ||
scope: [ 'inserter' ], | ||
}, | ||
], |
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.
Do we still need the variations
? I think we tried this approach to work around the issue with detecting inner blocks, but it looks like we'd be avoiding this issue now anyway if we go with the legacy
attribute as discussed during our call 🙂
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.
Good point @ockham. I'll remove the variations
attribute. 👍
In my opinion, whether a block contains inner blocks or not (during So even if My suggestion is to investigate how to add this information to the Block API in a way that:
If you do so, please add it to the Block API tracking issue #41236. |
Totally agree; that's even coupled with the |
@spacedmonkey, sorry for the ping! I should have created this PR as a draft from the beginning. 😅 All the code you reviewed, I copy-pasted it from /packages/block-library/src/post-comments/index.php, which is basically the behavior we want to include as a fallback after merging the blocks. I'll have in mind your suggestions, though. 😄 |
Just because the code is copied from elsewhere, doesn't mean it should be just accepted into this new block. As the old block does seem to have unit tests, it hard to valid how it meant to work. I have 9 years of experience working on WordPress core and I am a core committer. Hopefully some of feedback is actioned. |
@ockham, I'm not sure how to handle styles. Do we need to keep the old class name? Can we include styles only if the block version is the legacy one? 🤔 |
Good question! In cases like these, I like to consult #32514 for prior art 😄 I found this, so I think we should keep the old class name. (But yeah, in our case, we'd only need to keep the class name around if |
I have another question regarding styles, though. I'm not sure if this is feasible, but it would be ideal if the old CSS code for Is there a way to not include |
It seems there is not a way for that in _wp_multiple_block_styles and I'm not sure if we can use another filter for that.. --cc @aristath I haven't checked the code in this PR but maybe an alternative could be to transform the legacy styles to |
I don't think it's possible to do it in the editor... However, on the frontend I think it should be possible to do it 🤔 |
This is a significant change for a minor point release so I went ahead and removed this issue from the 6.0.1 editor tasks board and also removed the backport label @ockham. LMK if you disagree! |
Yeah, it's kind of a big change 🤔 I think my main rationale for including it in 6.0.1 would be that the Comments block is still fairly fresh -- WP 6.0 was the first release that had it included, and that deprecated the Post Comments block. In a way, merging those two blocks is the logical continuation of that deprecation. We'd discussed it previously with @gziolo, who seemed in favor of including it in 6.0.1. But yeah, I get your concerns; it wouldn't hurt to have a bit more time to test this... 🤔 |
e2c5688
to
a79556e
Compare
Co-authored-by: Bernie Reiter <[email protected]>
Co-authored-by: Bernie Reiter <[email protected]>
Co-authored-by: Bernie Reiter <[email protected]>
I saw some unrelated e2e tests that seem to fail randomly. 😅 They didn't pass two commits ago, and now they did. |
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 a lot for all your work on this @DAreRodz, and thanks for everyone who weighed in to makes this happen! 🙌
LGTM 😎
I'm going to merge this PR, so it doesn't keep growing. 😅 🚀 As a follow-up, we can go deeper into @spacedmonkey suggestion of using
Another thing I've noticed is that the block renders in those cases where the diff --git a/packages/block-library/src/comments/index.php b/packages/block-library/src/comments/index.php
index 5df2ed550a..ef8c98e391 100644
--- a/packages/block-library/src/comments/index.php
+++ b/packages/block-library/src/comments/index.php
@@ -62,6 +62,10 @@ function render_block_core_comments( $attributes, $content, $block ) {
$output = ob_get_clean();
$post = $post_before;
+ if ( empty( $output ) ) {
+ return '';
+ }
+
$classnames = array();
// Adds the old class name for styles' backwards compatibility.
if ( isset( $attributes['legacy'] ) ) { |
Thanks @DAreRodz! Your reasoning about
I've filed #42737 for this, but was struggling to reproduce in what cases |
EDIT: moved my answer here. |
Tracking issue: #41451
What?
Merge the Comments block into the Post Comments block. This PR is WIP and continues the work in #40522.
The idea is to end up with a single block comprising both blocks:
More info in #40521.
We could also take this opportunity to change the Comments block ID from
core/comments-query-loop
tocore/comments
and end up with something like this:Why?
See #40522 (comment)
How?
The block differentiates between the "legacy" PHP mode and the editable mode using an attribute called
legacy
. That property isfalse
by default, and it's only set totrue
when converting the old Post Comments into the Comments block. The block conversion is automatically done when you open the WP editor.The block is either static or dynamic depending on the value of
legacy
(false
ortrue
, respectively).Testing Instructions
<!-- wp:comments {"legacy":true} /-->
. Close the code editor.switch
button. Now, inner blocks should appear.legacy
attribute (it isfalse
by default) and should contain rendered markup and inner blocks.Other things to test: