Do not notify plugins after their uninstall function has been called (#12098)

Fixes #12032
This commit is contained in:
Bojidar Marinov
2025-07-12 19:29:51 +03:00
committed by GitHub
parent 4a62c17b1c
commit 6372280085
2 changed files with 32 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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']);
});
});
});