From d314a20b810e6f99f60606bfd387456129f9ea5d Mon Sep 17 00:00:00 2001 From: Jordi Bunster Date: Wed, 3 Mar 2021 21:59:43 -0800 Subject: [PATCH] Fix subscription leak (#465) * Fix subscription leak * Update src/Explorer/SplashScreen/SplashScreen.tsx Co-authored-by: Laurent Nguyen * Array needs to exist in the first place Co-authored-by: Laurent Nguyen --- src/Explorer/SplashScreen/SplashScreen.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index c6e55c7c7..5fa305b28 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -41,19 +41,32 @@ export class SplashScreen extends React.Component { private static readonly failoverUrl = "https://docs.microsoft.com/azure/cosmos-db/high-availability"; private readonly container: Explorer; + private subscriptions: Array<{ dispose: () => void }>; constructor(props: SplashScreenProps) { super(props); this.container = props.explorer; - this.container.tabsManager.openedTabs.subscribe(() => this.setState({})); - this.container.selectedNode.subscribe(() => this.setState({})); - this.container.isNotebookEnabled.subscribe(() => this.setState({})); + this.subscriptions = []; } public shouldComponentUpdate() { return this.container.tabsManager.openedTabs.length === 0; } + public componentWillUnmount() { + while (this.subscriptions.length) { + this.subscriptions.pop().dispose(); + } + } + + public componentDidMount() { + this.subscriptions.push( + this.container.tabsManager.openedTabs.subscribe(() => this.setState({})), + this.container.selectedNode.subscribe(() => this.setState({})), + this.container.isNotebookEnabled.subscribe(() => this.setState({})) + ); + } + private clearMostRecent = (): void => { MostRecentActivity.mostRecentActivity.clear(userContext.databaseAccount?.id); this.setState({});