2

When linking directly to a comment (via clicking on the comment's date to get the link in the URL), the Stack Exchange software places an anchor link in the URL (pointing to the comment's anchor) but otherwise leaves the URL unchanged.

The majority of links to comments are obtained by a user who visited the page via clicking on a link to the question, or via a link to a page of answers. There's nothing in the user interface that suggests clicking on a link to the answer (which, if you're on the question page already, doesn't seem to be anywhere in the interface other than the "share" link at the bottom of the screen), and only then generating a link to the comment. So when I see links to comments in practice, they're normally a link to the question (perhaps with URL parameters selecting a particular page of output), followed by the anchor for the comment.

These links work fine if the comment is in fact on the given page (i.e. the answer is on the same page of answers as it was when the permalink was generated, given the same sort order). However, answers have a tendency to move around in the sort order: they can be upvoted or downvoted and change page when sorted by votes; they can be edited and change page when sorted by active; and for users who can't see deleted posts, they can change page when posts that sort earlier are deleted (even when sorting by oldest). Additionally, answers will sort on a different page for users who can see deleted posts, and users who can't. If the answer that the comment's attached to isn't visible when the page is loaded, the comment won't be visible either, and so the link to the comment will become a broken link.

As an example, take this comment, which I arbitrarily selected from the PPCG Sandbox (a heavily answered, heavily active post on PPCG Meta). For me, it's currently on page 25 of answers when sorted by active (the post has a lot of answers; it's used to work on questions to get them up to a quality suitable for the site, and each question that we want to work on is posted as an answer to the post). I can see deleted posts on PPCG Meta; if you can't, the answer won't be on page 25 for you, and so the link to the comment won't work. Within a few weeks after I've posted this, the link will probably break for me too, when the answer gets pushed back to page 26 (alternatively, deleted answers may move it to page 24, or perhaps the post will even get edited and move to page 1).

This problem all stems from comment permalinks typically having the question number and answer page number and sort order in the URL. The most obvious way to fix the bug would be to place a link to the answer as the non-anchor portion of a comment permalink; that way, a comment permalink would necessarily load the page containing the answer, and thus be able to see the comment.

(It should be noted that this isn't a hypothetical problem, either. I found a link broken by it on Meta just now, which is what inspired me to post this question; in that instance the answer in question is one of the oldest answers on the question, so I suggested fixing it via setting the sort order to oldest page 1 (which would work for everyone), but linking to the answer is likely to be a more general fix.)

You must log in to answer this question.

Browse other questions tagged .