From a1578a9eab89f98bb78dfe7ba7aac21b77c43d69 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Sat, 21 Mar 2020 12:36:45 +0000 Subject: [PATCH] [ML] Fixing app clean up --- x-pack/plugins/ml/public/application/app.tsx | 65 +++++++++----------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/x-pack/plugins/ml/public/application/app.tsx b/x-pack/plugins/ml/public/application/app.tsx index 6269c11fca896..8c3e0c066f411 100644 --- a/x-pack/plugins/ml/public/application/app.tsx +++ b/x-pack/plugins/ml/public/application/app.tsx @@ -23,45 +23,16 @@ type MlDependencies = MlSetupDependencies & MlStartDependencies; interface AppProps { coreStart: CoreStart; deps: MlDependencies; - appMountParams: AppMountParameters; } const localStorage = new Storage(window.localStorage); -const App: FC = ({ coreStart, deps, appMountParams }) => { - setDependencyCache({ - indexPatterns: deps.data.indexPatterns, - timefilter: deps.data.query.timefilter, - fieldFormats: deps.data.fieldFormats, - autocomplete: deps.data.autocomplete, - config: coreStart.uiSettings!, - chrome: coreStart.chrome!, - docLinks: coreStart.docLinks!, - toastNotifications: coreStart.notifications.toasts, - overlays: coreStart.overlays, - recentlyAccessed: coreStart.chrome!.recentlyAccessed, - basePath: coreStart.http.basePath, - savedObjectsClient: coreStart.savedObjects.client, - application: coreStart.application, - http: coreStart.http, - security: deps.security, - urlGenerators: deps.share.urlGenerators, - }); - - const mlLicense = setLicenseCache(deps.licensing); - - appMountParams.onAppLeave(actions => { - mlLicense.unsubscribe(); - clearCache(); - return actions.default(); - }); - +const App: FC = ({ coreStart, deps }) => { const pageDeps = { indexPatterns: deps.data.indexPatterns, config: coreStart.uiSettings!, setBreadcrumbs: coreStart.chrome!.setBreadcrumbs, }; - const services = { appName: 'ML', data: deps.data, @@ -85,10 +56,34 @@ export const renderApp = ( deps: MlDependencies, appMountParams: AppMountParameters ) => { - ReactDOM.render( - , - appMountParams.element - ); + setDependencyCache({ + indexPatterns: deps.data.indexPatterns, + timefilter: deps.data.query.timefilter, + fieldFormats: deps.data.fieldFormats, + autocomplete: deps.data.autocomplete, + config: coreStart.uiSettings!, + chrome: coreStart.chrome!, + docLinks: coreStart.docLinks!, + toastNotifications: coreStart.notifications.toasts, + overlays: coreStart.overlays, + recentlyAccessed: coreStart.chrome!.recentlyAccessed, + basePath: coreStart.http.basePath, + savedObjectsClient: coreStart.savedObjects.client, + application: coreStart.application, + http: coreStart.http, + security: deps.security, + urlGenerators: deps.share.urlGenerators, + }); - return () => ReactDOM.unmountComponentAtNode(appMountParams.element); + const mlLicense = setLicenseCache(deps.licensing); + + appMountParams.onAppLeave(actions => actions.default()); + + ReactDOM.render(, appMountParams.element); + + return () => { + mlLicense.unsubscribe(); + clearCache(); + ReactDOM.unmountComponentAtNode(appMountParams.element); + }; };