From 04749ed098428c1b3e97807d5a6d36bb8a00af12 Mon Sep 17 00:00:00 2001 From: Tomoyuki Hata <7702653+hata6502@users.noreply.github.com> Date: Wed, 14 Apr 2021 23:49:22 +0900 Subject: [PATCH] Prevent the leak of codex-tooltip when Editor.js is destroyed (#1590) * Prevent the leak of codex-tooltip when Editor.js is destroyed * Cover destroy() function Thanks, @hata6502 --- docs/CHANGELOG.md | 5 ++++- package.json | 2 +- src/components/modules/api/tooltip.ts | 7 +++++++ src/components/modules/toolbar/index.ts | 1 + src/components/modules/toolbar/inline.ts | 1 + src/components/modules/toolbar/toolbox.ts | 1 + src/components/utils.ts | 4 ++++ src/components/utils/sanitizer.ts | 4 ---- src/components/utils/tooltip.ts | 7 +++++++ yarn.lock | 8 ++++---- 10 files changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 14571e87..bf3b9198 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 2.20.2 + +- `Fix` - Prevent the leak of codex-tooltip when Editor.js is destroyed [#1475](https://github.com/codex-team/editor.js/issues/1475). + ### 2.20.1 - `Fix` - Create a new block when clicked at the bottom [#1588](https://github.com/codex-team/editor.js/issues/1588). @@ -14,7 +18,6 @@ - `New` — [Block Tunes API](block-tunes.md) added - ### 2.19.3 - `Fix` — Ignore error raised by Shortcut module diff --git a/package.json b/package.json index 31fb793d..5b0d6708 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,6 @@ }, "dependencies": { "codex-notifier": "^1.1.2", - "codex-tooltip": "^1.0.1" + "codex-tooltip": "^1.0.2" } } diff --git a/src/components/modules/api/tooltip.ts b/src/components/modules/api/tooltip.ts index 74796baa..30bb6585 100644 --- a/src/components/modules/api/tooltip.ts +++ b/src/components/modules/api/tooltip.ts @@ -29,6 +29,13 @@ export default class TooltipAPI extends Module { this.tooltip = new Tooltip(); } + /** + * Destroy Module + */ + public destroy(): void { + this.tooltip.destroy(); + } + /** * Available methods */ diff --git a/src/components/modules/toolbar/index.ts b/src/components/modules/toolbar/index.ts index 7ed3e28c..56953d91 100644 --- a/src/components/modules/toolbar/index.ts +++ b/src/components/modules/toolbar/index.ts @@ -406,5 +406,6 @@ export default class Toolbar extends Module { */ private destroy(): void { this.removeAllNodes(); + this.tooltip.destroy(); } } diff --git a/src/components/modules/toolbar/inline.ts b/src/components/modules/toolbar/inline.ts index a100f15c..4c3d29b3 100644 --- a/src/components/modules/toolbar/inline.ts +++ b/src/components/modules/toolbar/inline.ts @@ -298,6 +298,7 @@ export default class InlineToolbar extends Module { } this.removeAllNodes(); + this.tooltip.destroy(); } /** diff --git a/src/components/modules/toolbar/toolbox.ts b/src/components/modules/toolbar/toolbox.ts index 62916d87..4c9eb175 100644 --- a/src/components/modules/toolbar/toolbox.ts +++ b/src/components/modules/toolbar/toolbox.ts @@ -128,6 +128,7 @@ export default class Toolbox extends Module { this.removeAllNodes(); this.removeAllShortcuts(); + this.tooltip.destroy(); } /** diff --git a/src/components/utils.ts b/src/components/utils.ts index 8e17379d..5a82dec7 100644 --- a/src/components/utils.ts +++ b/src/components/utils.ts @@ -661,6 +661,8 @@ export function cacheable( /** * Override get or value descriptor property to cache return value + * + * @param args */ descriptor[propertyToOverride] = function (...args: Arguments): Value { /** @@ -675,6 +677,8 @@ export function cacheable( /** * If get accessor has been overridden, we need to override set accessor to clear cache + * + * @param value */ if (propertyToOverride === 'get' && descriptor.set) { const originalSet = descriptor.set; diff --git a/src/components/utils/sanitizer.ts b/src/components/utils/sanitizer.ts index 1eb42b58..692c05b5 100644 --- a/src/components/utils/sanitizer.ts +++ b/src/components/utils/sanitizer.ts @@ -117,7 +117,6 @@ function deepSanitize(dataToSanitize: object | string, rules: SanitizerConfig): } } - /** * Clean array * @@ -186,6 +185,3 @@ function cleanOneItem(taintString: string, rule: SanitizerConfig|boolean): strin function isRule(config: SanitizerConfig): boolean { return _.isObject(config) || _.isBoolean(config) || _.isFunction(config); } - - - diff --git a/src/components/utils/tooltip.ts b/src/components/utils/tooltip.ts index 010039d1..a0ace016 100644 --- a/src/components/utils/tooltip.ts +++ b/src/components/utils/tooltip.ts @@ -17,6 +17,13 @@ export default class Tooltip { */ private lib: CodeXTooltips = new CodeXTooltips(); + /** + * Release the library + */ + public destroy(): void { + this.lib.destroy(); + } + /** * Shows tooltip on element with passed HTML content * diff --git a/yarn.lock b/yarn.lock index 590d15eb..d578f65d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2956,10 +2956,10 @@ codex-notifier@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/codex-notifier/-/codex-notifier-1.1.2.tgz#a733079185f4c927fa296f1d71eb8753fe080895" -codex-tooltip@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/codex-tooltip/-/codex-tooltip-1.0.1.tgz#f6e4f39d81507f9c455b667f1287746d14ee8056" - integrity sha512-1xLb1NZbxguNtf02xBRhDphq/EXvMMeEbY0ievjQTHqf8UjXsD41evGk9rqcbjpl+JOjNgtwnp1OaU/X/h6fhQ== +codex-tooltip@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/codex-tooltip/-/codex-tooltip-1.0.2.tgz#81a9d3e2937658c6e5312106b47b9f094ff7be63" + integrity sha512-oC+Bu5X/zyhbPydgMSLWKoM/+vkJMqaLWu3Dt/jZgXS3MWK23INwC5DMBrVXZSufAFk0i0SUni38k9rLMyZn/w== coffeeify@3.0.1: version "3.0.1"