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

Next Comments Block: Link showing on the last page when selecting a custom "items per page" setting. #37560

Closed
cbravobernal opened this issue Dec 21, 2021 · 4 comments · Fixed by #39227
Labels
[Block] Comments Affects the Comments Block - formerly known as Comments Query Loop [Type] Bug An existing feature does not function as intended

Comments

@cbravobernal
Copy link
Contributor

What problem does this address?

The error is available near the end of the video:

Screen.Recording.2021-12-21.at.14.54.26.mov

When selecting a custom setting for items per page, the Next Comments links show up even when we are on the last page.
Similar to #37553

What is your proposed solution?

We will check why is happening after we land #37297 and create a PR accordingly.

@cbravobernal cbravobernal added [Type] Bug An existing feature does not function as intended [Block] Comments Affects the Comments Block - formerly known as Comments Query Loop labels Dec 21, 2021
@cbravobernal cbravobernal changed the title [Next Comments Block] - Link showing on the last page when selecting a custom "items per page" setting. Next Comments Block: Link showing on the last page when selecting a custom "items per page" setting. Dec 21, 2021
@gziolo gziolo added Good First Issue An issue that's suitable for someone looking to contribute for the first time and removed Good First Issue An issue that's suitable for someone looking to contribute for the first time labels Feb 9, 2022
@gziolo
Copy link
Member

gziolo commented Feb 17, 2022

It looks like there is the only one case where the link to Older and Newer Comments are wrongly displayed is with these settings:

Screenshot 2022-02-17 at 10 55 42

There should be Older Comments rather than Newer Comments link:

Screenshot 2022-02-17 at 10 55 35

@SantosGuillamot
Copy link
Contributor

There is another related use case where the pagination is not working properly.

When the option "Last page displayed by default" is enabled, and you go to the penultimate page, the "Next Comments" link is pointing to #comments, which is wrong.

I've been running some tests (I will create a PR later) and it seems this is caused by the get_comments_pagenum_link function, used by these blocks. It is adding this conditional if ( 'newest' === get_option( 'default_comments_page' ) && $pagenum = $max_page ) and, when that happens, it doesn't create the link properly. Removing that check seems to solve this issue.

Steps to reproduce

1 - Enable the "Last page displayed by default" setting.
Screenshot 2022-02-17 at 10 55 42
2 - Go to a post with comments pagination and go to the penultime page.
3 - You can check that the "Next Comments" link is pointing to #comments instead of the proper page.
Screenshot 2022-03-04 at 18 49 34

@hellofromtonya
Copy link
Contributor

Issue: block's settings do not override global settings

I can reproduce ✔️

Test Report

Env

  • OS: macOS Big Sur
  • Localhost: wp-env
  • Browsers: Edge, Firefox, Chrome, and Safari
  • Theme: TT2

Setup and Testing Steps

  • Go to Settings > Discussion and set these settings:
    • Check Break comments into pages
    • 2 top level comments per page
    • first page displayed by default
    • older comments at the top of each page
      Screen Shot 2022-03-09 at 3 55 37 PM
  • Go to Posts > Add New to create a new post
  • Add in the Comments Query Loop block with these settings
    • Order by: Newest to oldest
    • Default page: Newest
    • Items per Page: 3

Screen Shot 2022-03-09 at 3 55 30 PM

  • Publish the post
  • View on the front end
  • Add 10 comments (not replies)
  • Refresh the page
  • Click on 2 in the Comments Query Loop block's pagination
  • Hover over the Older Comments link and notice its URL
  • Click on the Older Comments link. Expected behavior: it should go to page 1.

Results

When on cpage=2, the Older Comments link's URL does not have a cpage query var.
When clicking it goes to the last page of the comments.

WrongOlderCommentsLInkURL

Values:

  • cpage's value is correct without having to set it via set_query_var().
  • get_option( 'default_comments_page' ) is set to oldest

Call stack

  • gutenberg_render_block_core_comments_pagination_previous() calls get_previous_comments_link()
  • get_previous_comments_link()
    • gets the cpage query var value (which is 2) and subtracts 1 from it, i.e. to point to the previous page
    • calls get_comments_pagenum_link() passing a 1 to it as the previous page number
  • get_comments_pagenum_link() See the code here.)
    • grabs the page's URL
    • checks the first conditional which fails as get_option( 'default_comments_page' ) is oldest not newest
    • checks if the previous page number is > 1 => it's not so it skips this conditional check too

Thinking here

It's not due to cpage as that is being set correctly. Rather, it's because get_comments_pagenum_link() is not aware of the block's local settings but rather is using the global settings.

What about classic themes like TT0 and TT1?

TT1 and TT0 are using paginate_comments_links() which calls paginate_links() where the next ("newer") and previous ("older") links do always have the cpage query var in the URL.

classiccomments

Next steps

  • Investigate why the pagination code is different in paginate_links().
  • Explore making get_comments_pagenum_link() block local settings aware.

@ironprogrammer
Copy link
Contributor

In response to @hellofromtonya:

Investigate why the pagination code is different in paginate_links().

TT0 and TT1 utilize paginate_links() to generate ALL comment navigation links, including prev/next AND the numeric pagination. This is enabled by setting $args['prev_next'] = true. "Previous" links generated by this function always include the comments page slug, e.g. comment-page-1 (code reference). This matches the test result's "Older Comments" link that was reported above.

For comparison, TT2 utilizes paginate_links() ONLY for the pagination links (i.e. $args['prev_next'] = false), and uses get_previous_comments_link() and get_next_comments_link() to generate prev/next links. The "previous" link generated in this case specifically omits the comments page slug when the default comments page is "first" and the previous page's index is 1 (code reference).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Comments Affects the Comments Block - formerly known as Comments Query Loop [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants