Plotly.react resets context and breaks autosize
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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