Skip to content

Commit 6372280

Browse files
authored
Do not notify plugins after their uninstall function has been called (#12098)
Fixes #12032
1 parent 4a62c17 commit 6372280

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/core/core.plugins.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {callback as callCallback, isNullOrUndef, valueOrDefault} from '../helper
1919

2020
export default class PluginService {
2121
constructor() {
22-
this._init = [];
22+
this._init = undefined;
2323
}
2424

2525
/**
@@ -38,12 +38,17 @@ export default class PluginService {
3838
this._notify(this._init, chart, 'install');
3939
}
4040

41+
if (this._init === undefined) { // Do not trigger events before install
42+
return;
43+
}
44+
4145
const descriptors = filter ? this._descriptors(chart).filter(filter) : this._descriptors(chart);
4246
const result = this._notify(descriptors, chart, hook, args);
4347

4448
if (hook === 'afterDestroy') {
4549
this._notify(descriptors, chart, 'stop');
4650
this._notify(this._init, chart, 'uninstall');
51+
this._init = undefined; // Do not trigger events after uninstall
4752
}
4853
return result;
4954
}

test/specs/core.plugin.tests.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,5 +480,31 @@ describe('Chart.plugins', function() {
480480
await jasmine.triggerMouseEvent(chart, 'pointerleave', {x: 0, y: 0});
481481
expect(results).toEqual(['beforetest', 'aftertest', 'beforemouseout', 'aftermouseout']);
482482
});
483+
484+
it('should not call plugins after uninstall', async function() {
485+
const results = [];
486+
const chart = window.acquireChart({
487+
options: {
488+
events: ['test'],
489+
plugins: {
490+
testPlugin: {
491+
events: ['test']
492+
}
493+
}
494+
},
495+
plugins: [{
496+
id: 'testPlugin',
497+
reset: () => results.push('reset'),
498+
afterDestroy: () => results.push('afterDestroy'),
499+
uninstall: () => results.push('uninstall'),
500+
}]
501+
});
502+
chart.reset();
503+
expect(results).toEqual(['reset']);
504+
chart.destroy();
505+
expect(results).toEqual(['reset', 'afterDestroy', 'uninstall']);
506+
chart.reset();
507+
expect(results).toEqual(['reset', 'afterDestroy', 'uninstall']);
508+
});
483509
});
484510
});

0 commit comments

Comments
 (0)