Links to a line of code that is initially in a collapsed block of code will not display that line until manually expended

Summary

When reviewing a Merge Request, it is possible to get a link to an individual line of code.
When that line lies in a collapsed code block, like unchanged lines, or collapsed file (which happens for bigger files); the generated link will open the merge request, but will not point to the target line, until the block in which it belongs is manually expanded.
This in turn can lead to significant confusion in a workflow, when you receive such a link from a coworker, that ends up not pointing to the line it is originally intended to point to.

Steps to reproduce

This applies to this version of GitLab (GitLab Enterprise Edition 12.10.0-pre cc49b6fe), but also to GitLab Community Edition 12.9.2 and possibly any older versions.

  1. Open any merge request's diff (the Changes tab).
  2. Find a collapsed block of code.
  3. Expand it.
  4. Get a link for a line of code (right click on the line number) residing in this now expanded block of code.

Example (from this very GitLab repository)

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29769/diffs#2e5474fcec97fab2dbb3d269b6d3231e56252ad8_29_30
Please note: This linked merge request was chosen randomly, has nothing to do with this bug, and is just used for demonstration purposes.
This issue can be reproduced on any merge request, of any repository.

As is, this link should display line 29_30 of file app/assets/javascripts/monitoring/components/dashboard.vue upon opening (targeting the anchor #2e5474fcec97fab2dbb3d269b6d3231e56252ad8_29_30).
This is not the case, until you click to expand the second unchanged lines block of that file.

What is the current bug behavior?

When reproduced as explained in Steps to reproduce and upon opening the copied link :
The opened page is the right merge request's change tab, but the intended line is not displayed at all.

What is the expected correct behavior?

When reproduced as explained in Steps to reproduce and upon opening the copied link :
The opened page should display up top the actual linked line, highlighted.
The related collapsed code-block would have been automatically "expanded".

Possible fixes

When such a link is opened, and it contains a line number,
The location of that line should be determined, to know if it is in part of "collapsed" code-block; meaning it hasn't been loaded at all.
If so, the block shall be "expanded", by triggering the code that does load that block.
Navigation to the target line should then occurs automatically as it does when that block is manually expended after opening such a link.

Edited by Clément Fiere