Using the Linked File feature and the line_code URL fragment with only a single file causes unresolvable errors
Problem
When using the Linked File feature, a defect with the addLineReferences
method called from the ADD_CONTEXT_LINES
mutation is exposed.
This call triggers an uncaught fatal error, which is displayed in the UI as multiple errors that can't be resolved as long as the URL contains both the ?file=[sha]
search parameter and the #[sha]_n_n
line code.
Expected Behavior
- There should not be visible errors
- The Linked file feature should continue to work
Replication
- Create an MR that modifies a single file
- Leave a comment on the Diff file
- Either:
- Enable the Linked File feature by adding the code from !181163 (merged) OR
- Get the file hash for the file
- Use the same step here depending on how you got the file hash in the URL in the previous step:
- Click the filename in the Diff file header above your comment on the Overview tab
- Click the filename in the Diff file header above your comment on the Overview tab and add the file hash to the URL before any
#
fragments like:?file=[hash]#...
Possible fixes
Partial call stack
fetchLinkedExpandedLine
loadMoreLines
ADD_CONTEXT_LINES
-
addLineReferences
👈🏻 Fatal error is thrown here, astargetLine
is undefined. The sought index is out of bounds in previous lines, resulting in no line being returned.
Context
The following discussion from !181163 (merged) should be addressed:
-
@thomasrandolph started a discussion: There is a known bug exposed by this change that shows multiple errors on the Changes tab when the line that is linked to does not refer to a valid line in the other version (old vs. new).
For example, if the linked discussion points to new line 5, but the old file only had 3 lines, the Changes tab will show multiple errors. Everything will still work, but - in addition to multiple errors - there's a big button that says "Reload page", which results in the same error.
- These errors are unrelated to these changes but are exposed by the overlap of the
?file=[sha]
parameter enabling Linked Files and the#[sha]_n_n
hash linking to a line directly. - Because the button simply reloads the page, the user is stuck in an unresolvable loop / invalid error condition.
- These errors are unrelated to these changes but are exposed by the overlap of the