From b41f8164b8d48ee3ff52b75abe06791a347896bb Mon Sep 17 00:00:00 2001 From: Tim Down <158919+timdown@users.noreply.github.com> Date: Tue, 8 Apr 2025 08:46:56 +0100 Subject: [PATCH] Merge pull request #24709 from overleaf/td-prevent-spellcheck-after-destroy Prevent spell checks after spell checker is destroyed GitOrigin-RevId: 070f6c6ed05063e46960dad8099d61f585d6120c --- .../extensions/spelling/spellchecker.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts b/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts index eecccf5787..84054a8183 100644 --- a/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts +++ b/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts @@ -21,6 +21,7 @@ export class SpellChecker { private waitingForParser = false private firstCheckPending = false private trackedChanges: ChangeSet + private destroyed = false private readonly segmenter?: Intl.Segmenter // eslint-disable-next-line no-useless-constructor @@ -60,6 +61,7 @@ export class SpellChecker { destroy() { this._clearPendingSpellCheck() + this.destroyed = true } _abortRequest() { @@ -260,10 +262,22 @@ export class SpellChecker { } spellCheckAsap(view: EditorView) { + if (this.destroyed) { + debugConsole.warn( + 'spellCheckAsap called after spellchecker was destroyed. Ignoring.' + ) + return + } this._asyncSpellCheck(view, 0) } scheduleSpellCheck(view: EditorView) { + if (this.destroyed) { + debugConsole.warn( + 'scheduleSpellCheck called after spellchecker was destroyed. Ignoring.' + ) + return + } this._asyncSpellCheck(view, 1000) }