Skip to content

Fix private keys of the previous figure that leak into Plotly.react, relayout and restyle - #8217

Open
akysil wants to merge 1 commit into
plotly:mainfrom
akysil:fix/8210-bug-values-computed-for-the-previous-fig
Open

akysil wants to merge 1 commit into
plotly:mainfrom
akysil:fix/8210-bug-values-computed-for-the-previous-fig

Conversation

@akysil

@akysil akysil commented Nov 30, 2026

Copy link
Copy Markdown

Fixes #8210. The four cases of the issue no longer keep values of the previous figure after the update.

Cause

Plots.supplyDefaults copies every private (_) key that the new full trace or layout lacks from the old one (relinkPrivateKeys). A key that the defaults step sets only under a condition thus stays in the next figure.

Approach

Case Key Fix
1, rangebreaks removed xaxis._hasDayOfWeekBreaks axis_defaults.js sets the flag to false on every date axis
2, coloraxis removed trace._colorAx colorscale crossTraceDefaults deletes the key when the container has no coloraxis. This step runs after the relink.
3, axes with inside tick labels removed fullLayout._insideTickLabelsUpdaterange supplyDefaults resets the key before the layout relink. Axes.draw sets it again for the axes of the new figure.
4, contourcarpet replaced _carpetTrace, _a, _b and other carpet keys supplyDefaults relinks a trace only when the old and new trace types are the same

Cases 1 to 3 keep the trace type or concern layout keys, so they use explicit resets. constraints.js (_matchGroup) and the map layout defaults (_fitBounds) use the same pattern. For case 4, the check is on the type and not on one pair of types. contour and histogram2dcontour both draw through contour/plot.js, which reads _carpetTrace.

Tests

New jasmine tests:

  • axes_test.js, "more react tests": case 1 through Plotly.relayout and Plotly.react, and case 3
  • colorscale_test.js, "Test colorscale restyle calls": case 2 through Plotly.react and Plotly.restyle(gd, {coloraxis: [null]})
  • carpet_test.js, "contourcarpet plotting & editing": case 4 with a contour trace, with explicit distinct uids, and with a histogram2dcontour trace

The axes, colorscale and carpet suites ran on macOS. With the implementation files of main, the 6 new tests fail. With this change, they pass.

In the same targeted runs, axes_test.js "insiderange react to new data" fails with this change and with the implementation files of main. The lower bound is -0.181 where the test expects -0.173.

npm run lint and npm run typecheck pass. No image baselines move, because image mocks use a fresh newPlot.

The contour zmin/zmax key of #8117 is not part of this change (see #8122).

Rename draftlogs/XXXX_fix.md to the PR number after the PR opens.

Screenshots

In each picture, the left chart is the result of the update. The right chart is Plotly.newPlot of the same figure.

Weekend rangebreaks removed with Plotly.relayout: the x tick step (screenshots of the running app):

Before, upstream at 6c18375:

Weekend rangebreaks removed with Plotly.relayout: the x tick step, before

After, this branch:

Weekend rangebreaks removed with Plotly.relayout: the x tick step

Shared coloraxis replaced by one colorscale per heatmap with Plotly.react: the color bars and heatmap colors (screenshots of the running app):

Before, upstream at 6c18375:

Shared coloraxis replaced by one colorscale per heatmap with Plotly.react: the color bars and heatmap colors, before

After, this branch:

Shared coloraxis replaced by one colorscale per heatmap with Plotly.react: the color bars and heatmap colors

Two panels with inside tick labels reduced to one with Plotly.react: the red line is the error the update returned, and the trace width on the x axis (screenshots of the running app):

Before, upstream at 6c18375:

Two panels with inside tick labels reduced to one with Plotly.react: the red line is the error the update returned, and the trace width on the x axis, before

After, this branch:

Two panels with inside tick labels reduced to one with Plotly.react: the red line is the error the update returned, and the trace width on the x axis

🐦

Known limitations (follow-ups)

…previous figure

Plots.supplyDefaults copies private keys of the previous figure into the new one. Keys that the defaults step sets only under a condition then stay in the next figure.

Set _hasDayOfWeekBreaks on every date axis. Remove _colorAx when a container has no coloraxis. Clear _insideTickLabelsUpdaterange in supplyDefaults. Relink a trace only when the trace type is the same.

This branch has not been deployed

No deployments
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.

[BUG]: values computed for the previous figure leak into Plotly.react / relayout updates (four more cases like #8117)

1 participant