Fix "could not find out if split diff is enabled" on commented snippet
Created by: lguychard
Fixes #3480
Split diff detection, used on hover through getDiffCodePart()
, getCodeElementFromLineNumber()
, would inevitably throw an exception on PR commented snippets, because it relied on the presence of a toolbar allowing to switch between split diff / unified diff, which does not exist on PR discussions pages (commented snippets are always shown as a unified diff).
To fix this:
- I modified
getDiffCodePart()
to make sure that we check for hints on the hovered element before callingisSplitDomDiff()
: https://github.com/sourcegraph/sourcegraph/commit/19c3736e8ab54565eed1467e8f1b0887bbcbd14b - I scoped
isDomSplitDiff()
to an element passed as argument (either the code view itself, or an element contained in the code view), and checked for hints on the code view element, rather than checking for page-level hints: https://github.com/sourcegraph/sourcegraph/commit/c90f2ee4626b234167cb6f5684b22817471f96a9
I added fixtures for newly handled cases: pull request discussion * (GitHub.com, ghe) * (vanilla, refined GitHub).
Code Hosts
-
GitHub -
GitHub Enterprise -
Refined GitHub
Browsers
-
Chrome