From 38e64b710bf3b45bcbf51014eb0e1d6275de5325 Mon Sep 17 00:00:00 2001 From: cobyfrombrooklyn-bot Date: Sun, 22 Feb 2026 16:02:52 -0500 Subject: [PATCH] Fix splice with single argument throwing RangeError When calling data.splice(0) with only one argument, _onDataSplice computed newCount as arguments.length - 2 = -1, which is an invalid array length. Fixed by using Math.max(0, ...) to clamp to zero. Fixes #12191 --- src/core/core.datasetController.js | 2 +- test/specs/core.datasetController.tests.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 9b7126a93fd..094cb76b33a 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -1065,7 +1065,7 @@ export default class DatasetController { if (count) { this._sync(['_removeElements', start, count]); } - const newCount = arguments.length - 2; + const newCount = Math.max(0, arguments.length - 2); if (newCount) { this._sync(['_insertElements', start, newCount]); } diff --git a/test/specs/core.datasetController.tests.js b/test/specs/core.datasetController.tests.js index 18011efcb95..02ca491835c 100644 --- a/test/specs/core.datasetController.tests.js +++ b/test/specs/core.datasetController.tests.js @@ -538,6 +538,28 @@ describe('Chart.DatasetController', function() { expect(controller.getParsed(2)).toBe(data[2]); }); + it('should handle splice with a single argument without throwing (issue #12191)', function() { + var data = [0, 1, 2, 3, 4, 5]; + var chart = acquireChart({ + type: 'line', + data: { + datasets: [{ + data: data, + }], + }, + }); + + var meta = chart.getDatasetMeta(0); + + expect(function() { + data.splice(0); + chart.update(); + }).not.toThrow(); + + expect(meta.data.length).toBe(0); + expect(data.length).toBe(0); + }); + it('should re-synchronize metadata when the data object reference changes', function() { var data0 = [0, 1, 2, 3, 4, 5]; var data1 = [6, 7, 8];