Fix preventScrollToFragment intercepting cross-page links
What does this MR do?
preventScrollToFragment was calling event.preventDefault() on every link click within its container, which broke regular navigation: clicking a link without a hash, or a link pointing to a different page, did nothing.
This MR restricts the default-prevention to same-page hash links only:
- Bail out early when the link has no hash.
- Bail out when the link's URL (ignoring the hash) does not match the current page URL.
The handler now only intercepts the case it was built for — clicking a fragment link that points to an element on the current page.
Where it manifested
The only consumer is the Rapid Diffs lineLinkAdapter (app/assets/javascripts/rapid_diffs/adapters/line_link.js), where the listener is attached to the diff body. With linked-file params now baked into line link hrefs, those URLs can resolve to a different file/page — clicking them used to be silently no-ops because of the unconditional preventDefault().
How to reproduce
- Enable Rapid Diffs on merge requests
- Open any merge request
- Select 'Changes' tab
- Leave a comment with a link on any line
- Click on that link
- Observe the click on link to work