Comment pagination sometimes jumps back to top of page on works, always does so on news posts
For a news post, the URL will look like: https://test.archiveofourown.org/admin_posts/###?show_comments=true#comments
For a single chapter work, the URL will look like: https://test.archiveofourown.org/works/###?show_comments=true#comments
For a multi chapter work, the URL will look like: https://test.archiveofourown.org/works/###?show_comments=true&view_full_work=true#comments
What should happen
When you use the pagination to navigate between pages of comments, the page that is loaded should have a comments anchor on the end of its URL, e.g. https://test.archiveofourown.org/admin_posts/###?page=2&show_comments=true#comments, which should position the comment form at the top of the screen (or the kudos section, if you’re using a work).
What does happen
In reality, this never appears to happen with news posts. It sometimes appears to happen with works.
Tested while logged in, with preferences set to show full work by default and not to warn for adult content. It seems more likely to keep the anchor on works rated Explicit, Mature, or Not Rated, but I am not 100% sure that is the key. redsummernight notes that if they access a work while logged out and have to navigate past the adult content warning, the comments anchor is lost on the pagination (i.e. if you start at https://test.archiveofourown.org/works/704022?show_comments=true&view_full_work=true#comments, following “Proceed” takes you to https://test.archiveofourown.org/works/704022?show_comments=true&view_adult=true&view_full_work=true#comments, and then the anchor disappears when following one of the pagination links.)
Just to reiterate, this only applies when loading comments via the URL parameters, not AJAX. That has its own issues ( AO3-5204 ).
Work 1 - Put comment box at the top of the page
News post - Went to top of page
Test Work - Put comment box at the top of the page
Test News Post - Put comment box at the top of the page
Tested with https://archiveofourown.org/admin_posts/13694 on Beta (400+ comments) and https://test.archiveofourown.org/admin_posts/668 on Staging.
All looks good to me 👍🏻
Reproduced the problem with works with one of my own on Beta and then checked the behaviour on Test:
logged out and went to https://archiveofourown.org/chapters/1089522?show_comments=true#comments (last chapter of one of my fics on Beta with 3 pages of comments) and https://test.archiveofourown.org/works/109413 (single-chapter work on Test with 2 pages of comments).
clicked on Comments, which took me down to the comments section and added #comments to the URL.
Navigate to page 2 of the comments. On Beta, the #comment anchor link disappeared from the URL, and I was back at the top of the page. On Test, the anchor remains and when the page refreshes, the browser skips to the comments section so this checks out for works. 👍🏻
Still need to test news posts next
I think this is probably the right fix, but I already have more PRs than I’m comfortable with, so I don’t want to submit another one right now: