Remove custom plot plugins when Canvas is unmounted (#90722)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Clint Andrew Hall 2021-02-10 12:19:13 -06:00 committed by GitHub
parent 4881306419
commit 20ddd39610
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,8 @@ import { i18n } from '@kbn/i18n';
import { Provider } from 'react-redux';
import { BehaviorSubject } from 'rxjs';
import { includes, remove } from 'lodash';
import { AppMountParameters, CoreStart, CoreSetup, AppUpdater } from 'kibana/public';
import { CanvasStartDeps, CanvasSetupDeps } from './plugin';
@ -39,6 +41,11 @@ import { initFunctions } from './functions';
// @ts-expect-error untyped local
import { appUnload } from './state/actions/app';
// @ts-expect-error Not going to convert
import { size } from '../canvas_plugin_src/renderers/plot/plugins/size';
// @ts-expect-error Not going to convert
import { text } from '../canvas_plugin_src/renderers/plot/plugins/text';
import './style/index.scss';
const { ReadOnlyBadge: strings } = CapabilitiesStrings;
@ -147,6 +154,17 @@ export const initializeCanvas = async (
export const teardownCanvas = (coreStart: CoreStart, startPlugins: CanvasStartDeps) => {
destroyRegistries();
// Canvas pollutes the jQuery plot plugins collection with custom plugins that only work in Canvas.
// Remove them when Canvas is unmounted.
// see: ../canvas_plugin_src/renderers/plot/plugins/index.ts
if (includes($.plot.plugins, size)) {
remove($.plot.plugins, size);
}
if (includes($.plot.plugins, text)) {
remove($.plot.plugins, text);
}
// TODO: Not cleaning these up temporarily.
// We have an issue where if requests are inflight, and you navigate away,
// those requests could still be trying to act on the store and possibly require services.