From: Bojidar Marinov Date: Sat, 12 Jul 2025 16:29:51 +0000 (+0300) Subject: Do not notify plugins after their uninstall function has been called (#12098) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;p=thirdparty%2FChart.js.git Do not notify plugins after their uninstall function has been called (#12098) Fixes #12032 --- diff --git a/src/core/core.plugins.js b/src/core/core.plugins.js index 6de827589..c73a2a1c2 100644 --- a/src/core/core.plugins.js +++ b/src/core/core.plugins.js @@ -19,7 +19,7 @@ import {callback as callCallback, isNullOrUndef, valueOrDefault} from '../helper export default class PluginService { constructor() { - this._init = []; + this._init = undefined; } /** @@ -38,12 +38,17 @@ export default class PluginService { this._notify(this._init, chart, 'install'); } + if (this._init === undefined) { // Do not trigger events before install + return; + } + const descriptors = filter ? this._descriptors(chart).filter(filter) : this._descriptors(chart); const result = this._notify(descriptors, chart, hook, args); if (hook === 'afterDestroy') { this._notify(descriptors, chart, 'stop'); this._notify(this._init, chart, 'uninstall'); + this._init = undefined; // Do not trigger events after uninstall } return result; } diff --git a/test/specs/core.plugin.tests.js b/test/specs/core.plugin.tests.js index 4b06e6f43..76f7b7109 100644 --- a/test/specs/core.plugin.tests.js +++ b/test/specs/core.plugin.tests.js @@ -480,5 +480,31 @@ describe('Chart.plugins', function() { await jasmine.triggerMouseEvent(chart, 'pointerleave', {x: 0, y: 0}); expect(results).toEqual(['beforetest', 'aftertest', 'beforemouseout', 'aftermouseout']); }); + + it('should not call plugins after uninstall', async function() { + const results = []; + const chart = window.acquireChart({ + options: { + events: ['test'], + plugins: { + testPlugin: { + events: ['test'] + } + } + }, + plugins: [{ + id: 'testPlugin', + reset: () => results.push('reset'), + afterDestroy: () => results.push('afterDestroy'), + uninstall: () => results.push('uninstall'), + }] + }); + chart.reset(); + expect(results).toEqual(['reset']); + chart.destroy(); + expect(results).toEqual(['reset', 'afterDestroy', 'uninstall']); + chart.reset(); + expect(results).toEqual(['reset', 'afterDestroy', 'uninstall']); + }); }); });