import defaults from './core.defaults';
import registry from './core.registry';
+import {isNullOrUndef} from '../helpers';
import {callback as callCallback, mergeIf, valueOrDefault} from '../helpers/helpers.core';
/**
}
invalidate() {
- this._oldCache = this._cache;
- this._cache = undefined;
+ // When plugins are registered, there is the possibility of a double
+ // invalidate situation. In this case, we only want to invalidate once.
+ // If we invalidate multiple times, the `_oldCache` is lost and all of the
+ // plugins are restarted without being correctly stopped.
+ // See https://github.com/chartjs/Chart.js/issues/8147
+ if (!isNullOrUndef(this._cache)) {
+ this._oldCache = this._cache;
+ this._cache = undefined;
+ }
}
/**
expect(plugin.hook).not.toHaveBeenCalled();
});
+
+ it('should not restart plugins when a double register occurs', function() {
+ var results = [];
+ var chart = window.acquireChart({
+ plugins: [{
+ start: function() {
+ results.push(1);
+ }
+ }]
+ });
+
+ Chart.register({id: 'abc', hook: function() {}});
+ Chart.register({id: 'def', hook: function() {}});
+
+ chart.update();
+
+ // The plugin on the chart should only be started once
+ expect(results).toEqual([1]);
+ });
});
});