Unfold the folded start of a multiline diff note range
What does this MR do and why?
This MR makes the diff show the whole range of a multiline diff comment, even when the range starts on lines that are hidden between diff hunks.
A multiline comment is anchored on the last line of its range. When diffs load, GitLab expands hidden lines only around that anchor line. So if a reviewer expands the context above a hunk and comments on a range starting there, the comment shows up with its first lines hidden again on the next load: the range header says "lines 51 to 62", but lines 51 to 54 are folded.
Now, behind the unfold_diff_note_line_range_start flag, the diff also expands around the first line of the range, and each expansion reaches towards the other end of the range within its hidden block. This applies to Rapid Diffs and the classic diffs page, and to the diff hunk stored with a note. Ranges that end on a changed line and start on a hidden line are now considered for expansion too; before, they were skipped entirely.
The old file version is only read when a range start is actually hidden. Ranges that start on a line already in the diff cost one scan of the diff lines in memory.
Known limits:
- When a range spans several hunks, hidden blocks in the middle of the range stay folded. Only the blocks holding the start and the end are expanded.
- A range covering a long hidden stretch expands all of it on every diff load.
The diffs batch response cache key includes the flag state, so turning the flag on takes effect on the next load. Turning it off can take up to an hour, because expanded lines stay in the diff highlight cache, as they already do for the existing note-line expansion.
References
- Related to #639557 (bug report)
- Feature flag rollout issue: #639548
- Example comment: !268520 (comment 4208413799) (range starts on new line 51, the hunk starts at new line 55)
Screenshots or screen recordings
Rapid Diffs, a comment on lines 3 to 8 of files/ruby/popen.rb where the hunk starts at line 6, with the thread hovered to highlight its range. Before, lines 3 to 5 stay folded and the hover highlights nothing, because the range's first line is not on the page. Captured from a local feature spec run.
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Enable the feature flag in the Rails console:
Feature.enable(:unfold_diff_note_line_range_start) - Open the Changes tab of a merge request.
- Above a hunk, click the expand button to show hidden lines.
- Start a multiline comment on one of the newly shown lines, drag it down into the hunk, and submit it.
- Reload the page. The commented range is fully shown, including the lines above the hunk.
- Disable the flag and clear the merge request's diff highlight cache, then reload. The lines above the hunk are folded again.
Feature.disable(:unfold_diff_note_line_range_start) MergeRequest.find(<id>).diffs.clear_cache
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

