Old-school comment URL #fragments still don't display correct page

Created on 9 January 2010, over 14 years ago
Updated 29 August 2023, 10 months ago

Problem/Motivation

Comment links used to look like this:

/node/17#comment-42

Let's call this the classic comment link. In general it does not workโ€”never did, except if the comment happened to be on the very first page of a node display.

Drupal 7 has, thankfully, been fixed, however, the fix works only with new-format comment links that look like this:

/node/17?comment=42#comment-42

The reason for this, is that Drupal on the server (i.e. PHP in general) has no way of reading the hash part of the URL, so it has to be duplicated in the query/search part.

All preexisting classic links all over the world still don't work properly and never will, unless we do something about it.

Proposed resolution

A simplified version of the working code for issue #677082: Comment links - JavaScript solution โ†’ could be used to allow foreign links, i.e. classic comment links on non-Drupal pages to work. This would work as follows.

  1. User clicks on classic comment link on a non-Drupal web page.
  2. The Drupal server cannot process this link properly and opens the very first page.
  3. Once the page is open, the JavaScript code checks the link and discovers that it is a classic comment link.
  4. The JavaScript program looks at the hash part of the URL (yes, JavaScript can do that) and checks whether the targetted comment is indeed on the current page.
  5. If not, the program reformats the link to the new format and calls up the page again, this time with the proper comment query included.
  6. Now that Drupal learns about the desired comment, it opens the proper page.

This requires two page calls in the hopefully infrequent case that the desired comment happens not to be on the first page.

Remaining tasks

patch

User interface changes

JS based URL redirection for "classic" comment links to the current format for pagination

API changes

none

Original report by @hgmichna โ†’

...

(Not to be mixed up with Creedence Clearwater Revival :-)

I'm proposing this for 7.x-dev, because it is closely related to issue #26966: Fix comment links when paging is used. โ†’ , which has recently been closed with success, and because it is a very small change that does hardly interfere with existing code. If not that, let it go for 8.x-dev.

....

An odd recognition on the side is that we could use much simpler, nicer links that look almost like the classic ones:

/node/17?comment=42

An additional, even smaller piece of JavaScript would have to look at the URL after the page is loaded and jump down to the desired comment, just as the browser does on its own when presented with the hash part, #comment-42. Very similar code already exists in issue #677082: Comment links - JavaScript solution โ†’ , so there wouldn't even be much work to do. I think it can't hurt to add that bit of code as well. Perhaps in a few years that could become the most favored comment link format.

Nothing would preclude the continued use of the additional, redundant hash part, so these formats could exist side by side.

...

๐Ÿ› Bug report
Status

Closed: outdated

Version

9.5

Component
Commentย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany hgmichna

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    It probably would have made sense to fix this in 2010, but we haven't been producing old-style comment links for over 15 years now, so there are probably not many left even as ancient linkrot. Marking outdated.

Production build 0.69.0 2024