-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Remove query alteration from build_comment_query_vars_from_block()
#6291
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
You can test this by adding the comment block to a singular page using an FSE "block" theme and turning on comment pagination. |
Test |
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 report and I'm sorry for introducing the problem in the first place. As shared below, this code was introduced in this pull request solving another bug, and we assumed it made sense to update cpage
because it is actually the comments page.
More context can be found in this comment, but basically the bug was that when visiting a post with comments ordered from newest to oldest, the pagination links weren't showing as expected:
We might want to take a look at different alternatives rather than just removing that code.
// Set the `cpage` query var to ensure the previous and next pagination links are correct | ||
// when inheriting the Discussion Settings. | ||
if ( 0 === $page && isset( $comment_args['paged'] ) && $comment_args['paged'] > 0 ) { | ||
set_query_var( 'cpage', $comment_args['paged'] ); | ||
} |
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'm afraid removing this without other solutions will cause another bug. This code was introduced in this pull request for a reason. More context can be found there and in this comment that code was suggested. We might want to revisit other potential solutions to that bug. There are a few suggestions on that discussion, although it is a bit old.
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.
That might be because of an off-by-one error. Patching the query should not be considered a fix for the original error.
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.
As mentioned in this comment, I would probably fix the conditional to follow old comments approach instead of removing it. According to my tests, something like this should work:
if ( '' == get_query_var( 'cpage' ) && isset( $comment_args['paged'] ) && $comment_args['paged'] > 1 ) {
set_query_var( 'cpage', $comment_args['paged'] );
}
I recommend removing that code as proposed in this PR and fixing the cause that deemed the code necessary. |
I wouldn't presently merge this PR as it would cause a regression of comments pagination, as @SantosGuillamot mentioned, so we'd be trading one bug for another 😕 (We have e2e test coverage for the issue that was originally fixed by WordPress/gutenberg#39227, and I've verified that this PR would indeed break one of the tests. To reproduce, apply the diff locally and run I had a bit of a deeper look into comments pagination related functions. FWIW, the result of
However, that is what the (equally "classic") wordpress-develop/src/wp-includes/comment-template.php Lines 1596 to 1600 in dea027e
My impression is that what we're doing in the Comments Pagination blocks is largely following established WP Core practices, so we should probably continue to set the Maybe we can add an e2e test to cover the bug that this PR seeks to fix; that would make it easier to develop a solution that fixes both this issue without introducing a regression of WordPress/gutenberg#39227. |
I've been running some tests and it seems According to my tests, when I set the option to “show last page displayed by default”,
I've been using the Query Monitor plugin to check the value of For this reason, I believe this would require a deeper discussion about what is the expected value of |
@SantosGuillamot Thank you for your investigation! @sybrew It seems like we aren't able to find any discernible differences of how |
@DAreRodz and I dug a bit deeper into this issue today. With the TSF plugin installed and active, it was quite easy to reproduce that there's a difference between Classic Themes and Block Themes. We tried once again with the following settings: This resulted in the following markup for a post with 31 comments (first page): With TT1: <!doctype html>
<html lang="en-US" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hello world! - gutenberg</title>
<!-- The SEO Framework by Sybre Waaijer -->
<meta name="robots" content="max-snippet:-1,max-image-preview:large,max-video-preview:-1" />
<link rel="canonical" href="http://localhost:8888/?p=1" /> With TT4: <!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The SEO Framework by Sybre Waaijer -->
<meta name="robots" content="noindex,max-snippet:-1,max-image-preview:large,max-video-preview:-1" />
<meta name="description" content="Welcome to WordPress. This is your first post. Edit or delete it, then start writing!" /> Note the missing |
Howdy! Sorry for my absence. To reproduce the issue consistently:
The block HTML (click me to view)<!-- wp:paragraph -->
<p>Testing...</p>
<!-- /wp:paragraph -->
<!-- wp:comments -->
<div class="wp-block-comments"><!-- wp:comments-title /-->
<!-- wp:comment-template -->
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"40px"} -->
<div class="wp-block-column" style="flex-basis:40px"><!-- wp:avatar {"size":40,"style":{"border":{"radius":"20px"}}} /--></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:comment-author-name {"fontSize":"small"} /-->
<!-- wp:group {"style":{"spacing":{"margin":{"top":"0px","bottom":"0px"}}},"layout":{"type":"flex"}} -->
<div class="wp-block-group" style="margin-top:0px;margin-bottom:0px"><!-- wp:comment-date {"fontSize":"small"} /-->
<!-- wp:comment-edit-link {"fontSize":"small"} /--></div>
<!-- /wp:group -->
<!-- wp:comment-content /-->
<!-- wp:comment-reply-link {"fontSize":"small"} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:comment-template -->
<!-- wp:comments-pagination -->
<!-- wp:comments-pagination-previous /-->
<!-- wp:comments-pagination-numbers /-->
<!-- wp:comments-pagination-next /-->
<!-- /wp:comments-pagination -->
<!-- wp:post-comments-form /--></div>
<!-- /wp:comments --> Important: Add one comment to the post.Reproducing the issue, 1:
Reproducing the issue, 2:
Takeaway: Do not use Aside: @ockham's comment above mentions The SEO Framework (my plugin). It automatically sets "noindex" for paginated comments and removes the canonical URL to speed up deindexing unless the canonical URL is different from the expected request. This is intended behavior. The SEO Framework does not suffer from the bug this PR attempts to tackle because I implemented a patch as soon as I discovered the bug. |
Thanks a lot for the reproduction steps, those are really useful 🙂 I've been triaging it again, and I believe all the issues mentioned in this thread can be solved by changing this conditional to check These are the things I reproduced: Canonical URL appends #commentsAs reported by @sybrew here, the current implementation is adding With the suggested fix, the "Older"/"Newer" comments links keep working as expectedThe modified code was introduced to solve an issue with the Older/Newer comments links here. With the suggested fix, it keeps working as expected, while the rest of the issues are solved. Missing canonical URLAs reported by @ockham here, there wasn't a canonical tag caused by this logic. With the suggested fix, the canonical link is added as expected. With that in mind, I believe we should adapt the conditional to follow the old approach instead of removing it. @sybrew, Could you please confirm if that solves the issues you were facing and if everything keeps working as expected on your side? |
The main query should not be adjusted after it has been established. Using I recommend removing its usage and adjusting the off-by-one logic where necessary. The pagination query variables will flow from the requested URL and should not be tinkered with afterwards. |
It seems the logic to |
Correct. This issue was introduced back in 2008 via a patch, but its implications weren't apparent because With FSE, all the page's blocks, including the comment blocks, are parsed right before action Dump of actions until wp_head in the test scenario described in my earlier comment (click me to view)The comment: #6291 (comment)
In short, the old way was also wrong, and this mistake should not be repeated for the appeal of tradition. I already mentioned this in the ticket (comment:6) and its undesired implications because of existing filters (i.e., I believe the inconsistency following this patch in the comment block is acceptable. Especially since the Block Editor already largely deviates from the Classic Editor and is unaffected by the same filters, it's worth considering improving upon things with 16 years of gained knowledge. |
Thank you @sybrew for all the detailed insights. It’s super helpful to work on the proper fix. In particular all the nuances between the classic and block themes are extremely important here. Excellent work pointing it out so precisely which is crucial to make the good final decision. I have an idea to consider of how to apply the fix proposed but at the same time mitigate the impact explained by @sybrew. We could clone the global I saw the same pattern in other places. |
To corroborate this, here's an inconsistency in individual comments' permalinks that @DAreRodz and I found: |
If we get rid of the As suggested by @ockham , I believe it could be solved passing a new argument to I started a draft pull request to modify the comments block and pass it as an argument. It would need modifications in core functions receive In get_previous_comments_link and get_next_comments_link, wrap that line with something like this: if ( empty( $page ) ) {
$page = get_query_var( 'cpage' );
} Let me know what you think. I can help pushing that forward. |
I've created one pull request in core with these changes plus the ones needed to avoid causing the old bug: #7275. With that, along the relevant Gutenberg PR to modify the blocks, it should be possible to remove the |
Landed the alternative patch with https://core.trac.wordpress.org/changeset/59081. Thank you for all the help. |
Trac ticket: https://core.trac.wordpress.org/ticket/60806
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.