From d15a8c2b2fd2aa2717ddfc0c3039d34e6ff8d475 Mon Sep 17 00:00:00 2001 From: Omotayo Obafemi <33766411+obafemitayor@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:52:40 +0000 Subject: [PATCH] Added fix for memory leak issue (#2893) * Added fix for memory leak issue * Documented the fix in docs/CHANGELOG.md * v2.31.0 * Documented the fix in docs/CHANGELOG.md * Documented the fix in docs/CHANGELOG.md * Documented the fix in docs/CHANGELOG.md * Documented the fix in docs/CHANGELOG.md --------- Co-authored-by: Omotayo Obafemi Co-authored-by: Peter Savchenko --- docs/CHANGELOG.md | 1 + src/components/utils/shortcuts.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 73a8fc02..e3e4dd9d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,7 @@ - `Improvement` - The current block reference will be updated in read-only mode when blocks are clicked - `Fix` - codex-notifier and codex-tooltip moved from devDependencies to dependencies in package.json to solve type errors - `Fix` - Handle whitespace input in empty placeholder elements to prevent caret from moving unexpectedly to the end of the placeholder +- `Fix` - Fix the memory leak issue in `Shortcuts` class - `Fix` - Fix when / overides selected text outside of the editor - `DX` - Tools submodules removed from the repository diff --git a/src/components/utils/shortcuts.ts b/src/components/utils/shortcuts.ts index 8cf51ff9..967243d2 100644 --- a/src/components/utils/shortcuts.ts +++ b/src/components/utils/shortcuts.ts @@ -86,7 +86,15 @@ class Shortcuts { const shortcuts = this.registeredShortcuts.get(element); - this.registeredShortcuts.set(element, shortcuts.filter(el => el !== shortcut)); + const filteredShortcuts = shortcuts.filter(el => el !== shortcut); + + if (filteredShortcuts.length === 0) { + this.registeredShortcuts.delete(element); + + return; + } + + this.registeredShortcuts.set(element, filteredShortcuts); } /**