plotly / plotly/plotly.js

Plotly.react resets context and breaks autosize

Open
#4,856 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

When calling Plotly.react to update the chart it decides to completely reset the context if the config parameter is present (https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_api.js#L2698-L2706).

This breaks the autosize feature since the _hasZeroHeight state was moved to the context (in https://github.com/plotly/plotly.js/pull/3090/files#diff-2941ab69a12080c0633ff4ac8ea3aa83R493-R494).

The context._hasZeroHeight is always reset to undefined, but in the second render the gd.clientHeight is no longer zero. So the height of the svg-container div will set to 100%, causing all the plot container to have no height.

Then in the third render gd.clientHeight will be zero again, so the svg-container div gets its height properly defined.

And so on...

An workaround is to call Plotly.react without the config (if nothing in it changed), but when using react-plotly.js that isn't an option, as it always call Plotly.react using the full signature (https://github.com/plotly/react-plotly.js/blob/master/src/factory.js#L80-L85).

See https://codepen.io/nantunes/pen/abvXgbd to reproduce. Click the "Change data" button to toggle the data and call Plotly.react. Notice that the red container div shrinks (or expands) its height.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/plot_api/plot_api.js around lines 2698-2706 and reproduce the behavior with the linked CodePen by clicking “Change data.” Trace how Plotly.react resets context when config is present; done means autosize no longer oscillates or leaves the plot container without height, including the full-signature call used by react-plotly.js.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.