Fix Rapid Diffs line number clicks reloading the page

What this MR does

Fixes a bug where clicking a line number in the gutter of a diff on the merge request Changes tab (Rapid Diffs) caused a full page reload instead of just highlighting the line and updating the URL fragment. After the reload, the page came back in "linked file" mode, with the clicked file pinned to the top of both the diff list and the file browser.

The click handler now only lets the browser navigate away when the link genuinely points to a different page, and only swallows the click once it has confirmed the fragment resolves to something on the current page.

Root cause

preventScrollToFragment in app/assets/javascripts/lib/utils/scroll_utils.js is the click handler that the Rapid Diffs lineLinkAdapter attaches to the diff body. It compared the full link href (everything before the #) against the current URL, including query params, and let the browser navigate whenever they differed.

Rapid Diffs line number links intentionally carry linked-file query params (file_path, or old_path/new_path, plus line for expanded lines) so that a copied link opens straight to that file. Those params never match the current URL, so every line click was treated as a cross-page link.

This comparison was introduced in !234570 (merged), which fixed a real problem: the handler used to call event.preventDefault() on every click inside the diff body, breaking ordinary links such as one inside a diff comment. That fix is preserved; only the same-page comparison and the timing of preventDefault() change.

Reproduction steps

  1. Open any merge request with a diff (Rapid Diffs is on by default for the Changes tab).
  2. Go to the Changes tab.
  3. Click a line number in the gutter of any file.
  4. Before: the page reloads and comes back with that file pinned as the linked file. After: the line is highlighted in place and only the URL fragment changes.

Before / after

Before After

Merge request reports

Loading
Loading