Skip to content

Commit 4c1e206

Browse files
committed
Fix dependencies in useEffect()
1 parent 16a02fc commit 4c1e206

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/vs/workbench/contrib/positronPlots/browser/components/plotsContainer.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import './plotsContainer.css';
88

99
// React.
10-
import React, { useEffect, useState } from 'react';
10+
import React, { useEffect } from 'react';
1111

1212
// Other dependencies.
1313
import * as DOM from '../../../../../base/browser/dom.js';
@@ -66,8 +66,6 @@ export const PlotsContainer = (props: PlotContainerProps) => {
6666
const plotHeight = historyBottom ? props.height - historyPx : props.height;
6767
const plotWidth = historyBottom ? props.width : props.width - historyPx;
6868

69-
const [debounceTimer, setDebounceTimer] = useState<NodeJS.Timeout | undefined>(undefined);
70-
7169
useEffect(() => {
7270
// Ensure the selected plot is visible. We do this so that the history
7371
// filmstrip automatically scrolls to new plots as they are emitted, or
@@ -86,13 +84,12 @@ export const PlotsContainer = (props: PlotContainerProps) => {
8684
plotHistory.scrollTop = plotHistory.scrollHeight;
8785
}
8886
}
87+
}, [plotHistoryRef]);
8988

89+
useEffect(() => {
9090
// Propagate current render settings. Use a debouncer to avoid excessive
9191
// messaging to language kernels.
92-
if (debounceTimer) {
93-
clearTimeout(debounceTimer);
94-
}
95-
setDebounceTimer(setTimeout(() => {
92+
const debounceTimer = setTimeout(() => {
9693
props.positronPlotsService.setPlotsRenderSettings({
9794
size: {
9895
width: plotWidth,
@@ -101,8 +98,10 @@ export const PlotsContainer = (props: PlotContainerProps) => {
10198
pixel_ratio: DOM.getActiveWindow().devicePixelRatio,
10299
format: PlotRenderFormat.Png, // Currently hard-coded
103100
});
104-
}, 500));
105-
}, [plotWidth, plotHeight, props.positronPlotsService, plotHistoryRef, debounceTimer]);
101+
}, 500);
102+
103+
return () => clearTimeout(debounceTimer);
104+
}, [plotWidth, plotHeight, props.positronPlotsService]);
106105

107106
/**
108107
* Renders either a DynamicPlotInstance (resizable plot), a

0 commit comments

Comments
 (0)