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
This commit is contained in:
Tomoyuki Hata 2021-04-14 23:49:22 +09:00 committed by GitHub
parent 32ac52a62f
commit 04749ed098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 30 additions and 10 deletions

View file

@ -1,5 +1,9 @@
# Changelog # 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 ### 2.20.1
- `Fix` - Create a new block when clicked at the bottom [#1588](https://github.com/codex-team/editor.js/issues/1588). - `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 - `New` — [Block Tunes API](block-tunes.md) added
### 2.19.3 ### 2.19.3
- `Fix` — Ignore error raised by Shortcut module - `Fix` — Ignore error raised by Shortcut module

View file

@ -87,6 +87,6 @@
}, },
"dependencies": { "dependencies": {
"codex-notifier": "^1.1.2", "codex-notifier": "^1.1.2",
"codex-tooltip": "^1.0.1" "codex-tooltip": "^1.0.2"
} }
} }

View file

@ -29,6 +29,13 @@ export default class TooltipAPI extends Module {
this.tooltip = new Tooltip(); this.tooltip = new Tooltip();
} }
/**
* Destroy Module
*/
public destroy(): void {
this.tooltip.destroy();
}
/** /**
* Available methods * Available methods
*/ */

View file

@ -406,5 +406,6 @@ export default class Toolbar extends Module<ToolbarNodes> {
*/ */
private destroy(): void { private destroy(): void {
this.removeAllNodes(); this.removeAllNodes();
this.tooltip.destroy();
} }
} }

View file

@ -298,6 +298,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
} }
this.removeAllNodes(); this.removeAllNodes();
this.tooltip.destroy();
} }
/** /**

View file

@ -128,6 +128,7 @@ export default class Toolbox extends Module<ToolboxNodes> {
this.removeAllNodes(); this.removeAllNodes();
this.removeAllShortcuts(); this.removeAllShortcuts();
this.tooltip.destroy();
} }
/** /**

View file

@ -661,6 +661,8 @@ export function cacheable<Target, Value, Arguments extends any[] = any[]>(
/** /**
* Override get or value descriptor property to cache return value * Override get or value descriptor property to cache return value
*
* @param args
*/ */
descriptor[propertyToOverride] = function (...args: Arguments): Value { descriptor[propertyToOverride] = function (...args: Arguments): Value {
/** /**
@ -675,6 +677,8 @@ export function cacheable<Target, Value, Arguments extends any[] = any[]>(
/** /**
* If get accessor has been overridden, we need to override set accessor to clear cache * If get accessor has been overridden, we need to override set accessor to clear cache
*
* @param value
*/ */
if (propertyToOverride === 'get' && descriptor.set) { if (propertyToOverride === 'get' && descriptor.set) {
const originalSet = descriptor.set; const originalSet = descriptor.set;

View file

@ -117,7 +117,6 @@ function deepSanitize(dataToSanitize: object | string, rules: SanitizerConfig):
} }
} }
/** /**
* Clean array * Clean array
* *
@ -186,6 +185,3 @@ function cleanOneItem(taintString: string, rule: SanitizerConfig|boolean): strin
function isRule(config: SanitizerConfig): boolean { function isRule(config: SanitizerConfig): boolean {
return _.isObject(config) || _.isBoolean(config) || _.isFunction(config); return _.isObject(config) || _.isBoolean(config) || _.isFunction(config);
} }

View file

@ -17,6 +17,13 @@ export default class Tooltip {
*/ */
private lib: CodeXTooltips = new CodeXTooltips(); private lib: CodeXTooltips = new CodeXTooltips();
/**
* Release the library
*/
public destroy(): void {
this.lib.destroy();
}
/** /**
* Shows tooltip on element with passed HTML content * Shows tooltip on element with passed HTML content
* *

View file

@ -2956,10 +2956,10 @@ codex-notifier@^1.1.2:
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/codex-notifier/-/codex-notifier-1.1.2.tgz#a733079185f4c927fa296f1d71eb8753fe080895" resolved "https://registry.yarnpkg.com/codex-notifier/-/codex-notifier-1.1.2.tgz#a733079185f4c927fa296f1d71eb8753fe080895"
codex-tooltip@^1.0.1: codex-tooltip@^1.0.2:
version "1.0.1" version "1.0.2"
resolved "https://registry.yarnpkg.com/codex-tooltip/-/codex-tooltip-1.0.1.tgz#f6e4f39d81507f9c455b667f1287746d14ee8056" resolved "https://registry.yarnpkg.com/codex-tooltip/-/codex-tooltip-1.0.2.tgz#81a9d3e2937658c6e5312106b47b9f094ff7be63"
integrity sha512-1xLb1NZbxguNtf02xBRhDphq/EXvMMeEbY0ievjQTHqf8UjXsD41evGk9rqcbjpl+JOjNgtwnp1OaU/X/h6fhQ== integrity sha512-oC+Bu5X/zyhbPydgMSLWKoM/+vkJMqaLWu3Dt/jZgXS3MWK23INwC5DMBrVXZSufAFk0i0SUni38k9rLMyZn/w==
coffeeify@3.0.1: coffeeify@3.0.1:
version "3.0.1" version "3.0.1"