Skip to content

Keep dcc.Graph user zoom across new figures with the same uirevision - #4183

Closed
parisni wants to merge 2 commits into
plotly:devfrom
parisni:fix-graph-uirevision-sync
Closed

parisni wants to merge 2 commits into
plotly:devfrom
parisni:fix-graph-uirevision-sync

Conversation

@parisni

@parisni parisni commented Nov 23, 2026

Copy link
Copy Markdown

Fixes #4093.

Since #3882, plotly_relayout syncs user edits (zoomed axis range, ...) into the figure prop, and that update replots the graph. plotly.js then sees the edited value as an app-provided one: it no longer matches the pre-edit value stored in _fullLayout._preGUI, so the edit loses its uirevision protection and the next figure returned by a callback resets the zoom.

The fix, in plot(): before Plotly.react, while uirevision is unchanged, every _preGUI key whose incoming value equals the current user value gets its pre-edit value back. plotly.js keeps the user edit as it did before 4.4.1, and Patch updates built on the synced figure (#3810, test_grbs012) still keep it too.

The new test zooms with a real mouse drag: Plotly.relayout is not recorded in _preGUI, which is why test_grbs012 did not catch the regression. It fails on dev (range back to the full extent) and passes with the fix.

Contributor Checklist

  • This PR targets dev (fix or chore) or next (feature, new API, breaking change), see Which branch to target
  • I have broken down my PR scope into the following TODO tasks
    • restore the _preGUI values of synced user edits before Plotly.react
    • regression test with a mouse-drag zoom
  • I have run the tests locally and they passed (test_grbs012, test_grbs015; eslint, prettier, black, flake8)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md

Since plotly#3882, plotly_relayout syncs the user edit (e.g. a zoomed axis
range) into the figure prop, which replots it. plotly.js then sees the
edited value as an app-provided one: it no longer matches the pre-edit
value stored in _preGUI, so the edit loses its uirevision protection and
the next figure from a callback resets the zoom.

Before Plotly.react, put back the _preGUI value for every key whose
incoming value is the current user value, while uirevision is unchanged.
plotly.js keeps the user edit, and Patch updates built on the synced
figure (plotly#3810) still keep it too.

Fixes plotly#4093
@sonarqubecloud

Copy link
Copy Markdown

@parisni

parisni commented Nov 23, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate of #4102, which I missed before opening this one. It fixes the same regression (#4093) more thoroughly: it records the pre-edit value when the edit is synced, so it also covers a Patch applied between the zoom and the next figure.

One finding from this PR that may help the review of #4102: a test that zooms with Plotly.relayout does not reproduce the bug, because only GUI edits are recorded in _preGUI (that is why test_grbs012 passed). The test here zooms with a real mouse drag and fails on dev:
https://github.com/parisni/dash/blob/fix-graph-uirevision-sync/components/dash-core-components/tests/integration/graph/test_graph_basics.py

@parisni parisni closed this Nov 23, 2026
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] dcc.Graph loses zoom state with unchanged uirevision

1 participant