Skip to content

Handle URL hashes when loading an MR one file at a time

Thomas Randolph requested to merge tor/defect/single-file-scroll-to-note into master

What does this MR do and why?

For #403084 (closed)

Problem

Links to notes in the diffs app don't scroll to the note when single-file mode is enabled.

Cause

Ideally, an anchor that points to an element with that ID (as note links do) would just use normal browser behavior to scroll to anchors, without any custom code.

Unfortunately:

  1. The content is never available when the browser thinks the page is ready, which means the scroll never happens by default
  2. Our sticky elements make automatic ID scrolling unusable (they are hidden by sticky content)

What this means is we have to manually scroll to anchors in the URL, but in single-file mode, that scroll behavior is never triggered.

Solution

When a file is loaded in single-file mode, we trigger all of the appropriate state/store updates, and then call the "universal" handleLocationHash to process the anchor and scroll (if necessary).

Screenshots or screen recordings

Before After
RecApp-2023-10-03-10_54_16 RecApp-2023-10-03-10_35_10

How to set up and validate locally

See the related issue for example steps.

Broadly:

  1. Have an MR with a fairly long file (e.g. needs scrolling)
  2. Leave a comment far down in the file, which would require scrolling to put into the viewport
  3. Copy the URL to the note from the diffs app (e.g. xxx/n/diffs#note_nnn)
  4. Set your diffs preference to view MRs one file at a time
  5. Load the URL you copied

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Thomas Randolph

Merge request reports