From 9adfb0a92595900062d2cccd5b05bf8610f8e997 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Wed, 22 Mar 2023 15:58:44 +0530 Subject: [PATCH] refactor: fix noteviewcontroller de-init --- .../NoteView/Controller/NoteViewController.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts b/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts index cbb5ba624..02c96ecfa 100644 --- a/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts +++ b/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts @@ -38,7 +38,7 @@ export class NoteViewController implements ItemViewControllerInterface { private saveTimeout?: ReturnType private defaultTagUuid: UuidString | undefined private defaultTag?: SNTag - private savingLocallyPromise = Deferred() + private savingLocallyPromise: ReturnType> | null = null constructor( private application: WebApplication, @@ -59,6 +59,11 @@ export class NoteViewController implements ItemViewControllerInterface { } deinit(): void { + if (!this.savingLocallyPromise) { + this.performDeinitSafely() + return + } + void this.savingLocallyPromise.promise.then(() => { this.performDeinitSafely() }) @@ -212,7 +217,9 @@ export class NoteViewController implements ItemViewControllerInterface { void this.undebouncedSave({ ...params, onLocalPropagationComplete: () => { - this.savingLocallyPromise.resolve() + if (this.savingLocallyPromise) { + this.savingLocallyPromise.resolve() + } resolve() }, })