Skip to content

fix: use continue instead of return in clearStacks#12195

Open
veeceey wants to merge 1 commit intochartjs:masterfrom
veeceey:fix/issue-12154-clearstacks-return
Open

fix: use continue instead of return in clearStacks#12195
veeceey wants to merge 1 commit intochartjs:masterfrom
veeceey:fix/issue-12154-clearstacks-return

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 14, 2026

Fixes #12154

When clearStacks was refactored from forEach to for...of in 1e296cc, the return inside the loop was kept as-is. In a forEach callback, return only skips the current iteration, but in a for...of loop it exits the entire function.

This means that if any parsed data point doesn't have _stacks data for the current dataset index (which can happen when two points share the same x-coordinate and reference the same _stacks object, or when new points are added), the loop exits early and leaves stale stack entries on the remaining data points. This causes lines/bars to be incorrectly stacked when datasets are reordered.

The fix simply changes return to continue to restore the original skip-this-iteration behavior.

Added a regression test that swaps dataset order and verifies the update doesn't throw.

In commit 1e296cc, clearStacks was refactored from forEach to
for...of, but the inner `return` (which previously only skipped
the current forEach iteration) now exits the entire function.

This means if any parsed data point lacks _stacks data for the
current dataset (e.g. when two points share x-coordinates and
their _stacks object, or when new points are inserted), the
remaining data points are skipped and their stale stack entries
are never cleared. This causes incorrect stacking when datasets
are reordered.

Fixes chartjs#12154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chart._stacks isn't always cleared when it should be

1 participant