Skip to content

Harden reselect against empty/undefined calcdata entries#7820

Open
TheSisb wants to merge 1 commit into
plotly:masterfrom
TheSisb:fix-reselect-calcdata-guard
Open

Harden reselect against empty/undefined calcdata entries#7820
TheSisb wants to merge 1 commit into
plotly:masterfrom
TheSisb:fix-reselect-calcdata-guard

Conversation

@TheSisb
Copy link
Copy Markdown

@TheSisb TheSisb commented Jun 2, 2026

Skip empty/undefined calcdata entries in epmtySplomSelectionBatch and determineSearchTraces instead of dereferencing them.

What happens

reselect runs unconditionally at the end of every redraw sequence (newPlot / react / relayout / resize). Its helper epmtySplomSelectionBatch iterates gd.calcdata and dereferences cd[i][0] with no guard:

  for (var i = 0; i < cd.length; i++) {
      var cd0 = cd[i][0];   // throws if cd[i] is undefined
      var trace = cd0.trace;

When gd.calcdata contains an empty ([]) or undefined entry, this throws
and the redraw promise rejects:

  TypeError: Cannot read properties of undefined (reading '0')
      at epmtySplomSelectionBatch (src/components/selections/select.js)
      at reselect             (src/components/selections/select.js)
      at Plots.reselect       (src/plots/plots.js)
      at Lib.syncOrAsync      (src/lib/index.js)
      at relayout             (src/plot_api/plot_api.js)

reselect runs unconditionally at the end of every redraw sequence
(newPlot / react / relayout / resize). Its helper epmtySplomSelectionBatch
iterates gd.calcdata and dereferences cd[i][0] with no guard, so a transient
empty or undefined calcdata entry throws "Cannot read properties of undefined
(reading '0')" and kills the chart even when no selection exists.

The sibling supplyDefaultsUpdateCalc already guards the same access with
(oldCalcdata[i] || [])[0]; make epmtySplomSelectionBatch and determineSearchTraces
equally defensive by skipping empty/undefined entries.

Add a jasmine spec covering both cases.
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.

1 participant