/t/XYZ#anchor doesn't work when on the page XYZ

AI-generated summary

A user, Arthri, reports an issue with internal page links using short links and anchors (/t/id#anchor). When clicking such a link on the same page, the browser redirects to the top of the page instead of the intended anchor. Arthri provides a detailed demonstration with seven links and notes that most links (except the first) reload the page after briefly working, removing the anchor from the URL.

The problem occurs specifically when quoting a post containing an anchor link, causing it to become relative to the current page instead of the quoted page. Arthri attempted a solution from a related bug report (quoting-does-not-preserve-hyperlink/33141/2 referenced in mrmowji), but it only fixed the link destination and not the anchor. mrmowji further describes the reload as a “web-app” reloading with a progress bar, and suggests it may only happen the first time the topic is loaded.

Hello! There’s a problem where if a post links to itself using short link + an anchor (/t/id#anchor) and the link is clicked on the same page, it will redirect to the top rather than the anchor

It’s easier when demonstrated:

Header 1

  1. #header-1 works when tabbed on this thread
  2. https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1 works when tabbed on this thread and quoted
  3. https://meta.discourse.org/t/a/225101#header-1-1 works when tabbed on this thread and quoted
  4. https://meta.discourse.org/t/225101#header-1-1 works when not tabbed on this thread
  5. /t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1 works when tabbed on this thread and quoted
  6. /t/a/225101#header-1-1 works when tabbed on this thread and quoted
  7. /t/225101#header-1-1 works when not tabbed on this thread

There’s also two other problems I noticed. All links except the first will reload the page. Links 2, 3, 5 and 6 work but the header is removed from the url after a short amount of time


My original problem was quoting a post which contained a link with only anchor(a link to another section of the same page) would make the anchor relative to the current page rather than the quoted page. If you quote the seven links, the first link will lead to CURRENT PAGE#header-1

I tried the solution in this bug report(attached below). It correctly linked to the page, however, the anchor was not respected

1 Like

I have this for the #anchor variant too. It doesn’t reload the page always. Maybe only if I click on such anchors the first time the topic is loaded. Unfortunately, I can’t give you the exact steps.

And by “reload”, I don’t mean a refresh on the browser’s tab. I mean the “web-app” reloading; a progress bar shows up at the top of the viewport.