Skip to content

Commit

Permalink
fix(explore): double resize triggered (apache#24886)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored and pull[bot] committed Mar 22, 2024
1 parent 0e65dd4 commit f7eb31f
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { styled, t, logging } from '@superset-ui/core';
import { isEqual } from 'lodash';
import { debounce, isEqual } from 'lodash';
import { withRouter } from 'react-router-dom';

import { exportChart, mountExploreUrl } from 'src/explore/exploreUtils';
Expand Down Expand Up @@ -95,7 +95,7 @@ const defaultProps = {

// we use state + shouldComponentUpdate() logic to prevent perf-wrecking
// resizing across all slices on a dashboard on every update
const RESIZE_TIMEOUT = 350;
const RESIZE_TIMEOUT = 500;
const SHOULD_UPDATE_ON_PROP_CHANGES = Object.keys(propTypes).filter(
prop =>
prop !== 'width' && prop !== 'height' && prop !== 'isComponentVisible',
Expand Down Expand Up @@ -142,7 +142,7 @@ class Chart extends React.Component {
this.exportXLSX = this.exportXLSX.bind(this);
this.exportFullXLSX = this.exportFullXLSX.bind(this);
this.forceRefresh = this.forceRefresh.bind(this);
this.resize = this.resize.bind(this);
this.resize = debounce(this.resize.bind(this), RESIZE_TIMEOUT);
this.setDescriptionRef = this.setDescriptionRef.bind(this);
this.setHeaderRef = this.setHeaderRef.bind(this);
this.getChartHeight = this.getChartHeight.bind(this);
Expand Down Expand Up @@ -178,8 +178,7 @@ class Chart extends React.Component {
}

if (nextProps.isFullSize !== this.props.isFullSize) {
clearTimeout(this.resizeTimeout);
this.resizeTimeout = setTimeout(this.resize, RESIZE_TIMEOUT);
this.resize();
return false;
}

Expand All @@ -189,8 +188,7 @@ class Chart extends React.Component {
nextProps.width !== this.state.width ||
nextProps.height !== this.state.height
) {
clearTimeout(this.resizeTimeout);
this.resizeTimeout = setTimeout(this.resize, RESIZE_TIMEOUT);
this.resize();
}

for (let i = 0; i < SHOULD_UPDATE_ON_PROP_CHANGES.length; i += 1) {
Expand Down Expand Up @@ -224,7 +222,7 @@ class Chart extends React.Component {
}

componentWillUnmount() {
clearTimeout(this.resizeTimeout);
this.resize.cancel();
}

componentDidUpdate(prevProps) {
Expand Down

0 comments on commit f7eb31f

Please sign in to comment.