Change browser extension to use a single MutationObserver
Created by: felixfbecker
Refactors browser extension to use a single MutationObserver whose events are passed as an Observable to functions, instead of only injecting things once and never removing them. Code views are then detected inside added and removed nodes. When a node with a code view got removed, its state gets properly cleaned up.
It fixes a bunch of bugs/wrong assumptions I found - for example, switchMap was used on the codeViews Observable which could race to randomly drop code views, and the selections and view components code assumed only the latest code view emitted was relevant. Hoverify was never unsubscribed from.
Also does a few renames that made things less confusing for me, e.g. CodeView -> CodeViewSpec, CodeView.codeView -> CodeView.codeViewElement
Also removes a hacky MutationObserver workaround in favor of the real fix https://github.com/sourcegraph/codeintellify/pull/100
I've not touched unit tests yet. The functions that take MutationRecords can now be unit tested. Also not touched other code hosts than GitHub yet.
Fixes #2162 Fixes https://github.com/sourcegraph/sourcegraph/issues/2958 Fixes #3103 Fixes #955
Tested on
-
GitHub -
GitHub + Refined GitHub -
GitHub Enterprise -
Bitbucket Server -
Phabricator -
Gitlab
Merge request reports
Activity
Created by: felixfbecker
It seems like this change would be code host-agnostic. What do you have in mind?
There is a compile error in
client/browser/src/libs/phabricator/extension.tsxsinceinjectCodeIntelligence()is called but now needs themutationsObservable. I am not sure why this error is only in the Phab code. Maybe this is dead code?Created by: codecov[bot]
Codecov Report
Merging #2909 into master will decrease coverage by
3.69%. The diff coverage is61.4%.Impacted Files Coverage Δ ...wser/src/libs/code_intelligence/external_links.tsx 97.22% <ø> (-0.28%)
client/browser/src/libs/phabricator/util.tsx 7.56% <ø> (-0.64%)
.../browser/src/shared/components/CodeViewToolbar.tsx 27.02% <0%> (ø)
...lient/browser/src/libs/github/code_intelligence.ts 16.45% <0%> (+0.17%)
client/browser/src/libs/github/inject.tsx 17.46% <0%> (ø)
...t/browser/src/libs/bitbucket/code_intelligence.tsx 17.54% <100%> (ø)
.../browser/src/libs/phabricator/code_intelligence.ts 20.83% <100%> (ø)
...lient/browser/src/libs/gitlab/code_intelligence.ts 33.33% <100%> (ø)
client/browser/src/shared/util/dom.tsx 27.77% <44.44%> (+2.77%)
...r/src/libs/code_intelligence/code_intelligence.tsx 58.62% <65%> (+0.99%)
... and 92 more