From 6f13b956735bc91ab9d6a91e8b1f2b12147ef9cc Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Thu, 10 Jun 2021 14:05:14 +0200 Subject: [PATCH] fix(@mongodb-js/compass-shell): Terminate shell runtime when dataService disconnects or Compass is closed --- .../src/components/compass-shell/compass-shell.jsx | 11 +++++++++++ packages/compass-shell/src/stores/store.js | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/compass-shell/src/components/compass-shell/compass-shell.jsx b/packages/compass-shell/src/components/compass-shell/compass-shell.jsx index 80c456650c8..534b932affa 100644 --- a/packages/compass-shell/src/components/compass-shell/compass-shell.jsx +++ b/packages/compass-shell/src/components/compass-shell/compass-shell.jsx @@ -52,6 +52,11 @@ export class CompassShell extends Component { componentDidMount() { this.loadHistory(); + window.addEventListener('beforeunload', this.terminateRuntime); + } + + componentWillUnmount() { + window.removeEventListener('beforeunload', this.terminateRuntime); } onShellOutputChanged = (output) => { @@ -70,6 +75,12 @@ export class CompassShell extends Component { }); } + terminateRuntime = () => { + if (this.props.runtime) { + this.props.runtime.terminate(); + } + } + lastOpenHeight = defaultShellHeightOpened; resizableRef = null; diff --git a/packages/compass-shell/src/stores/store.js b/packages/compass-shell/src/stores/store.js index 1da583bb266..f428e495f63 100644 --- a/packages/compass-shell/src/stores/store.js +++ b/packages/compass-shell/src/stores/store.js @@ -42,6 +42,14 @@ export default class CompassShellStore { } onDataServiceDisconnected = () => { + const { + runtime: { runtime }, + } = this.reduxStore.getState(); + + if (runtime) { + runtime.terminate(); + } + this.reduxStore.dispatch(setupRuntime( null, null,