fix: clone calcParams and figures on indicator override to stop reference aliasing - #850
Open
NemeZZiZZ wants to merge 1 commit into
Open
fix: clone calcParams and figures on indicator override to stop reference aliasing#850NemeZZiZZ wants to merge 1 commit into
NemeZZiZZ wants to merge 1 commit into
Conversation
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.
Problem
Indicator.overrideassignscalcParamsandfiguresby reference, while every other field goes throughmerge/clone:Consequences:
IndicatorImp.extend(template)passes the template's arrays throughoverride, so every instance of a registered indicator shares onecalcParamsarray. Verified by execution:instance.calcParams === template.calcParams(strict reference equality).shouldUpdate._prevIndicatoris snapshotted after the mutation target is already shared, soJSON.stringify(prev.calcParams) === JSON.stringify(current.calcParams)and no recalculation happens — the chart keeps showing stale values even though the params changed.Fix
Assign clones instead of references:
clonereturns non-objects (including thestylescallback some figures carry) by reference, so function-valued figure properties are preserved.Verification
Against the real
typeChecks.tson Node: clonedcalcParamsare value-equal but reference-distinct; mutating the caller's array afteroverrideno longer leaks into the instance; figure objects are copied while theirstylescallbacks are preserved by reference.Note: a separate, related quirk —
merge()copies explicitly-passedundefined(overrideIndicator({ id, visible: undefined })clears visibility) — is in the sharedmergeutility and intentionally not bundled here.