Skip to content

Observe and react to URL hash changes in MR File-By-File mode

What does this MR do and why?

For #438716 (closed)

The single-file ("file-by-file") mode of MR review updates the hash value in the URL when a user interacts with the UI.
However, it doesn't equivalently react to that hash changing from outside the app (for example, when the user interacts with the browser's navigation controls).

This update adds an event listener that observes the browser's native hashchange event and loads the appropriate file: identified by the hash, or the first in the MR if no hash is in the URL.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
fbf-native-hashchange-before fbf-native-hashchange-after

How to set up and validate locally

(See the first three steps from the replication section of the triggering issue)

  1. Create/visit an MR with at least 2 changed files
  2. Activate "Show one file at a time" from the MR Settings dropdown menu
  3. Click a file from the file tree (this adds the file hash to the URL)
  4. Click another file from the file tree (this changes the hash in the URL)
  5. Use the browser's native back/forward button

Before: The URL updates properly, but the page does not update the displayed file.
After: The URL updates, and the page triggers a load for the correct file.

Edited by Thomas Randolph

Merge request reports