From ae83a693f44f1e6f38f0ae8d12eb07f0d38d7b6f Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Fri, 18 Mar 2022 09:01:22 +1000 Subject: [PATCH] Fix infinite spinner when trying to restore Send state (#2449) Clear state when re-opening popup --- src/popup/app.component.ts | 20 +++++++++++++++----- src/popup/send/send-groupings.component.ts | 3 +-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/popup/app.component.ts b/src/popup/app.component.ts index 771c696be3..9799e9d400 100644 --- a/src/popup/app.component.ts +++ b/src/popup/app.component.ts @@ -41,7 +41,11 @@ export class AppComponent implements OnInit { private platformUtilsService: PlatformUtilsService ) {} - ngOnInit() { + async ngOnInit() { + // Component states must not persist between closing and reopening the popup, otherwise they become dead objects + // Clear them aggressively to make sure this doesn't occur + await this.clearComponentStates(); + this.stateService.activeAccount.subscribe((userId) => { this.activeUserId = userId; }); @@ -125,10 +129,7 @@ export class AppComponent implements OnInit { (window as any).previousPopupUrl != null && (window as any).previousPopupUrl.startsWith("/tabs/") ) { - await this.stateService.setBrowserGroupingComponentState(null); - await this.stateService.setBrowserCipherComponentState(null); - await this.stateService.setBrowserSendComponentState(null); - await this.stateService.setBrowserSendTypeComponentState(null); + await this.clearComponentStates(); } if (url.startsWith("/tabs/")) { await this.stateService.setAddEditCipherInfo(null); @@ -250,4 +251,13 @@ export class AppComponent implements OnInit { confirmed: confirmed.value, }); } + + private async clearComponentStates() { + await Promise.all([ + this.stateService.setBrowserGroupingComponentState(null), + this.stateService.setBrowserCipherComponentState(null), + this.stateService.setBrowserSendComponentState(null), + this.stateService.setBrowserSendTypeComponentState(null), + ]); + } } diff --git a/src/popup/send/send-groupings.component.ts b/src/popup/send/send-groupings.component.ts index 32a2491cf2..8aebbfcd59 100644 --- a/src/popup/send/send-groupings.component.ts +++ b/src/popup/send/send-groupings.component.ts @@ -14,8 +14,7 @@ import { SyncService } from "jslib-common/abstractions/sync.service"; import { SendType } from "jslib-common/enums/sendType"; import { SendView } from "jslib-common/models/view/sendView"; -import { BrowserSendComponentState } from "src/models/browserSendComponentState"; - +import { BrowserSendComponentState } from "../../models/browserSendComponentState"; import { StateService } from "../../services/abstractions/state.service"; import { PopupUtilsService } from "../services/popup-utils.service";