Skip to content

Simplify blob view line highlighting logic

Administrator requested to merge fkling/blob-simplify-line-highlighting into main

Created by: fkling

Currently the line highlighting logic is triggered on every re-render of the component because the codeViewElements observable emits unconditionally on every render.

This was introduced to ensure that the highlighting logic runs after React updated the DOM, otherwise React would overwrite our changes.

In that case a simpler solution which avoids updating the highlighted lines if neither code nor position is to avoid using observables altogether and put the highlighting logic directly in useEffect, conditioned on file and position changes.

Still seems to work as expected:

https://user-images.githubusercontent.com/179026/177218893-902912e7-2cc9-4c2a-bcbe-8dee29cd1a67.mp4

Test plan

  • Open a file in Sourcegraph that imports a dependency so that you can us jump to definition.
  • Select any line.
  • Jump to definition in another file. The line should be highlighted.
  • Press the back button. The previously highlighted line in the previous file should be highlighted.

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading