Skip to content

Change browser extension to use a single MutationObserver

Warren Gifford requested to merge single-mutation-observer into master

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 (closed) Fixes https://github.com/sourcegraph/sourcegraph/issues/2958 Fixes #3103 (closed) Fixes #955 (closed)

Tested on

  • GitHub
  • GitHub + Refined GitHub
  • GitHub Enterprise
  • Bitbucket Server
  • Phabricator
  • Gitlab

Merge request reports

Loading