[go: up one dir, main page]

Use code review id instead of client-side diff ID in merge requests

What does this MR do and why?

This MR fixes #582822.

The original bug was caused by the fact that diff file id property was generated on the frontend. When the user marked some of the files as viewed, switched to the file-by-file mode and reloaded the page the viewed indicator became no longer reliable. This is because id is generated on the frontend and it needs diff file data, coming from the diffs_batch.json. In the file-by-file mode we only load the currently selected file data and preload some data in advance. Because this data might not be loaded yet the file browser might show incorrect viewed state (marked as not viewed when it was in fact viewed).

Previously we tried to solve that problem by using file_hash as the key to store the viewed state. But it had another problem: it was not reset when you pushed changes to the branch that affected the viewed files. You might've marked some of the files as viewed, changed them and they would stay as viewed, which is not expected.

To solve both of these problems we need to use an ID that is automatically reset after changes in the diff and is also available in both the diff file data and in the file browser. This new ID (code_review_id) was added in this MR: !215499 (merged)

This MR now uses this ID as a single source of truth for marking files as viewed. This ID was migrated from the frontend's generated id property, so the logic of resetting the id is exactly the same.

This MR also refactors the diffs store and extracts the logic for the viewed IDs into a separate store. This was done because the diffs store used two properties to define the same state: mrReviews and viewedDiffFileIds. That introduced a major ambiguity in code because we now had two separate sources of truth.

The new codeReview store solves that problem: it acts as a single source of truth for every viewed state, both in file browser and in the diffs list. It also provides backwards compatibility for the legacy id property generated on the frontend. If a user had reviewed some of the files prior to this change their code review will be preserved and automatically upgraded to the new code_review_id once they toggle the viewed checkbox on any of the files.

Screenshots or screen recordings

CleanShot_2025-12-13_at_03.56.32_2x

How to set up and validate locally

  1. Visit any merge request
  2. Mark some of the files as viewed
  3. Enable file-by-file mode
  4. Reload the page
  5. Observe all the viewed files to stay as viewed in the file browser
  6. Push changes that affect the viewed files
  7. Observe the viewed indicator to be reset for these files

Merge request reports

Loading