Repository navigation
fix(config): keep initialConfig unadulterated when series are hidden - #5280
Conversation
Fixes apexcharts#5118. globals.initialConfig is meant to be the config the chart started with: resetSeries, the toolbar reset-home button and custom tooltips all read it. Two things kept it from being that. Utils.extend() copies arrays by reference, because isObject() excludes them, so initialConfig.series was literally w.config.series. A legend collapse replaces series[i].data with [] in place, and the snapshot lost the data along with the live config. The re-capture on updateOptions(overwriteInitialConfig) then read the live series back, collapse state and all, so even an unrelated option change baked the emptied series into the baseline. That capture now moves only when the call actually redefines the series. The copy is per-series and shallow -- series objects copied, data arrays shared -- the same shape globals.initialSeries already captures, so snapshotting stays O(n) rather than deep-cloning every point. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Verified against One thing to sort out before this goes in. The comment above While you are in there: that setter does the identical per-series shallow copy inline, a few lines above the code you changed. Reusing On the deferred half: One test worth adding: |
Review follow-ups on apexcharts#5280. The lazy initialSeries setter did the same per-series shallow copy inline that Utils.copySeriesShallow() now does, a few lines below the comment that describes it. It calls the helper, so the two snapshots are the same shape by construction rather than by assertion. The comment claimed no in-place edit can reach a copy made this way. appendData()'s push loop is the exception, and it is not undone by re-capturing after the push: the pushed points are already in the array both snapshots point at. Both comments now name that exception instead of excluding it. Tests: updateOptions({ series }) while a series is collapsed, updateSeries not re-aliasing the live config, and both snapshots sharing data arrays while copying series objects. Co-Authored-By: Claude Opus 5 <[email protected]>
Review follow-ups on apexcharts#5280. The lazy initialSeries setter did the same per-series shallow copy inline that Utils.copySeriesShallow() now does, a few lines below the comment that describes it. It calls the helper, so the two snapshots are the same shape by construction rather than by assertion. The comment claimed no in-place edit can reach a copy made this way. appendData()'s push loop is the exception, and it is not undone by re-capturing after the push: the pushed points are already in the array both snapshots point at. Both comments now name that exception instead of excluding it. Tests: updateOptions({ series }) while a series is collapsed, updateSeries not re-aliasing the live config, and both snapshots sharing data arrays while copying series objects. Co-Authored-By: Claude Opus 5 <[email protected]>
c558207 to
2851985
Compare
|
All four are right; here is what I re-ran before agreeing. appendData. Reproduced, and it is not something this PR introduces: identical on I tried the re-capture you offered rather than assuming it works, dropping It cannot help. The pushed points are already inside the array both snapshots point at, so re-capturing copies the series object again and lands on the same data array; only copying the data arrays would detach it, which is the per-point cost the lazy snapshot exists to avoid. So I narrowed the claim in Measuring that turned up a second thing, pre-existing and equally true on } else {
// lazy snapshot: the globals setter stores a cheap per-series shallow
// copy; the deep clone materializes only if something reads it
gl.initialSeries = ser
}Out of scope here and not touched; say the word and I will file it separately. Dedup. Done: the setter is now resetSeries. Your correction is right and my "Not included" paragraph was not. Verified: Clearing the collapsed indices is not the issue; The test you asked for. Added. On One gap of my own. Reverting only the
Pushed as Not verified: only the jsdom unit suite: I did not run the e2e or Playwright interaction suites, and the appendData conclusions were measured in jsdom rather than a browser. |
|
Thanks for re-running all of this instead of taking my word for any of it. I redid the per-hunk table on my side and it comes out exactly as you have it, the behaviour-neutral setter row included. I also ran the gates against a merge with current You were right about the re-capture and I was wrong to suggest it. I dropped it into One correction to the narrowed comment, though. It says detaching would mean copying the data arrays, and there is a cheaper way out: let Good catch on the One small thing for next time: those 23 typecheck errors are not all in Nothing blocking from me. |
|
Ran your Stock main reads One nuance to carry into the follow-up with it: it detaches The You're right on the typecheck split, and "same 23 pre-existing Drilldown.js errors" was sloppy shorthand on my part. Re-counted on main: For the record, today's main is already past your merge-gate numbers (140 files / 3338 tests, zero failures), since the heatmap-shape spec landed after your run. Not verified here: jsdom only again, no browser or e2e runs behind any of the numbers above. |
Fixes #5118. The report points straight at
Series.js, and that turned out to be the symptom rather than the cause:globals.initialConfigwas never a snapshot at all.Why it emptied
Utils.extend()copies arrays by reference, becauseisObject()excludes them:So
globals.initialConfig = Utils.extend({}, config)leftinitialConfig.series === config.series, the very same array of the very same objects. A legend collapse replacesseries[i].datawith[]in place, and the "initial" config lost the data along with the live one.Fixing only that is not enough.
updateOptions()re-captures the snapshot fromw.config, which by then carries the collapse state, so an unrelated option change baked the emptied series back into the baseline. That capture now moves only when the call actually redefines the series; a plainupdateOptions({title})keeps the baseline it already had.The copy is per-series and shallow — series objects copied, data arrays shared — the same shape
globals.initialSeriesalready captures. Internal edits to a series' data are property replacements (series[i].data = [], orseries[i] = 0for non-axis charts) and neither can reach a copy made this way, so snapshotting stays O(n) instead of deep-cloning every point. That keeps the ~23ms-per-50k-update budget the lazyinitialSeriessnapshot was built to protect.Evidence
New spec
tests/unit/initial-config-hidden-series.spec.js, 4 tests. Onmain(b0dc6af), with the spec and without thesrc/change:Each half of the fix was then reverted on its own, to confirm neither test is vacuous:
Globals.jscapture onlyUpdateHelpers.jscapture onlyFull unit suite: 134 files, 3180 tests, 0 failures.
npm run lintclean.npm run typecheckreports the same 23 pre-existingDrilldown.jserrors asmain— the twoNonNullable<...>casts are there to keep that number from moving.Prettier: pre-existing deviations left alone, as on #5277.
prettier --writeon the touched files moves onlyUtils.js:432,UpdateHelpers.js:185,UpdateHelpers.js:304andUpdateHelpers.js:437, none of which are lines this PR adds.Not included
globals.initialSeriesis also refreshed from the live config during a collapse-driven re-render, so it carries the emptied series too. Nothing in this PR depends on that,resetSeriesclears the collapsed indices before restoring, and it predates this change — mentioning it here rather than widening the diff.