fix: use continue instead of return in clearStacks#12195
Open
veeceey wants to merge 1 commit intochartjs:masterfrom
Open
fix: use continue instead of return in clearStacks#12195veeceey wants to merge 1 commit intochartjs:masterfrom
veeceey wants to merge 1 commit intochartjs:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12154
When
clearStackswas refactored fromforEachtofor...ofin 1e296cc, thereturninside the loop was kept as-is. In aforEachcallback,returnonly skips the current iteration, but in afor...ofloop it exits the entire function.This means that if any parsed data point doesn't have
_stacksdata for the current dataset index (which can happen when two points share the same x-coordinate and reference the same_stacksobject, 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
returntocontinueto restore the original skip-this-iteration behavior.Added a regression test that swaps dataset order and verifies the update doesn't throw.