Handle URL hashes when loading an MR one file at a time
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:
- The content is never available when the browser thinks the page is ready, which means the scroll never happens by default
- 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:
- Have an MR with a fairly long file (e.g. needs scrolling)
- Leave a comment far down in the file, which would require scrolling to put into the viewport
- Copy the URL to the note from the diffs app (e.g.
xxx/n/diffs#note_nnn
) - Set your diffs preference to view MRs one file at a time
- 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.
-
I have evaluated the MR acceptance checklist for this MR.