Skip to content

Commit

Permalink
fix: remove double rendering
Browse files Browse the repository at this point in the history
Use only the ResizeObseerver to handle chart sizing at the initialization.

fix #690
  • Loading branch information
markov00 committed Jun 1, 2020
1 parent e2ba940 commit 1fd26fb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/components/chart_resizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface ResizerDispatchProps {

type ResizerProps = ResizerStateProps & ResizerDispatchProps;

const DEFAULT_RESIZE_DEBOUNCE = 200;

class Resizer extends React.Component<ResizerProps> {
private initialResizeComplete = false;
private containerRef: RefObject<HTMLDivElement>;
Expand All @@ -53,10 +55,8 @@ class Resizer extends React.Component<ResizerProps> {
componentDidMount() {
this.onResizeDebounced = debounce(this.onResize, this.props.resizeDebounce);
if (this.containerRef.current) {
const { clientWidth, clientHeight } = this.containerRef.current;
this.props.updateParentDimensions({ width: clientWidth, height: clientHeight, top: 0, left: 0 });
this.ro.observe(this.containerRef.current as Element);
}
this.ro.observe(this.containerRef.current as Element);
}

componentWillUnmount() {
Expand Down Expand Up @@ -102,11 +102,9 @@ const mapDispatchToProps = (dispatch: Dispatch): ResizerDispatchProps =>
);

const mapStateToProps = (state: GlobalChartState): ResizerStateProps => {
const settings = getSettingsSpecSelector(state);
const resizeDebounce =
settings.resizeDebounce === undefined || settings.resizeDebounce === null ? 200 : settings.resizeDebounce;
const { resizeDebounce } = getSettingsSpecSelector(state);
return {
resizeDebounce,
resizeDebounce: resizeDebounce == null || Number.isNaN(resizeDebounce) ? DEFAULT_RESIZE_DEBOUNCE : resizeDebounce,
};
};

Expand Down

0 comments on commit 1fd26fb

Please sign in to comment.