Skip to content

Commit acfc8e4

Browse files
authored
Merge pull request #3496 from plotly/cam/1263/fix-infinite-resize-loop
fix: Fix dcc.Graph infinite resize loop
2 parents 86788c8 + edc2917 commit acfc8e4

File tree

2 files changed

+22
-54
lines changed

2 files changed

+22
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2121
- [#3415](https://github.com/plotly/dash/pull/3415) Fix the error triggered when only a single no_update is returned for client-side callback functions with multiple Outputs. Fix [#3366](https://github.com/plotly/dash/issues/3366)
2222
- [#3416](https://github.com/plotly/dash/issues/3416) Fix DeprecationWarning in dash/_jupyter.py by migrating from deprecated ipykernel.comm.Comm to comm module
2323
- [#3488](https://github.com/plotly/dash/pull/3488) Fix pkgutil.find_loader removal in Python 3.14
24+
- [#3496](https://github.com/plotly/dash/pull/3496) Fix dcc.Graph infinite resize loop
2425

2526
## Deprecated
2627
- [#3482](https://github.com/plotly/dash/pull/3482) Deprecate dash_table.DataTable with replacement from `dash[ag-grid]` extra requirement.

components/dash-core-components/src/fragments/Graph.react.js

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ class PlotlyGraph extends Component {
393393

394394
gd.classList.add('dash-graph--pending');
395395

396+
// Calling resize enables layout.autosize in plotly.js
396397
Plotly.Plots.resize(gd)
397398
.catch(() => {})
398399
.finally(() => gd.classList.remove('dash-graph--pending'));
@@ -457,27 +458,6 @@ class PlotlyGraph extends Component {
457458
});
458459
}
459460

460-
getStyle() {
461-
const {responsive} = this.props;
462-
let {style} = this.props;
463-
464-
// When there is no forced responsive style, return the original style property
465-
if (!responsive) {
466-
return style;
467-
}
468-
469-
// Otherwise, if the height is not set, we make the graph size equal to the parent one
470-
if (!style) {
471-
style = {};
472-
}
473-
474-
if (!style.height) {
475-
return Object.assign({height: '100%'}, style);
476-
}
477-
478-
return style;
479-
}
480-
481461
componentDidMount() {
482462
const p = this.plot(this.props);
483463
this._queue = this.amendTraces(p, {}, this.props);
@@ -536,46 +516,33 @@ class PlotlyGraph extends Component {
536516
}
537517

538518
render() {
539-
const {className, id, loading_state} = this.props;
540-
const style = this.getStyle();
541-
542-
if (window.dash_component_api) {
543-
return (
544-
<LoadingElement
545-
id={id}
546-
key={id}
547-
className={className}
548-
style={style}
549-
ref={this.parentElement}
550-
>
551-
<ResizeDetector
552-
onResize={this.graphResize}
553-
targets={[this.parentElement, this.gd]}
554-
/>
555-
<div
556-
ref={this.gd}
557-
style={{height: '100%', width: '100%'}}
558-
/>
559-
</LoadingElement>
560-
);
519+
const {className, id, loading_state, style = {}} = this.props;
520+
if (this.isResponsive(this.props)) {
521+
style.height ||= '100%';
561522
}
523+
524+
let Container = LoadingElement;
525+
const containerProps = {
526+
className,
527+
id,
528+
key: id,
529+
ref: this.parentElement,
530+
style,
531+
};
532+
if (!window.dash_component_api) {
533+
Container = 'div';
534+
containerProps['data-dash-is-loading'] =
535+
loading_state?.is_loading || undefined;
536+
}
537+
562538
return (
563-
<div
564-
id={id}
565-
key={id}
566-
className={className}
567-
style={style}
568-
ref={this.parentElement}
569-
data-dash-is-loading={
570-
(loading_state && loading_state.is_loading) || undefined
571-
}
572-
>
539+
<Container {...containerProps}>
573540
<ResizeDetector
574541
onResize={this.graphResize}
575542
targets={[this.parentElement, this.gd]}
576543
/>
577544
<div ref={this.gd} style={{height: '100%', width: '100%'}} />
578-
</div>
545+
</Container>
579546
);
580547
}
581548
}

0 commit comments

Comments
 (0)