Skip to content

Commit 6fa52e9

Browse files
committed
Be defensive against invalid sizes
1 parent 4c1e206 commit 6fa52e9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export const DynamicPlotInstance = (props: DynamicPlotInstanceProps) => {
5151
const ratio = DOM.getActiveWindow().devicePixelRatio;
5252
const disposables = new DisposableStore();
5353

54+
// The frontend shoudn't send invalid sizes so be defensive. Sometimes the
55+
// plot container is in a strange state when it's hidden.
56+
if (props.height <= 0 || props.width <= 0) {
57+
return;
58+
}
59+
5460
// If the plot is already rendered, use the old image until the new one is ready.
5561
if (props.plotClient.lastRender) {
5662
setUri(props.plotClient.lastRender.uri);

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export const PlotsContainer = (props: PlotContainerProps) => {
6363

6464
const historyPx = props.showHistory ? HistoryPx : 0;
6565
const historyEdge = historyBottom ? 'history-bottom' : 'history-right';
66-
const plotHeight = historyBottom ? props.height - historyPx : props.height;
67-
const plotWidth = historyBottom ? props.width : props.width - historyPx;
66+
const plotHeight = historyBottom && props.height > 0 ? props.height - historyPx : props.height;
67+
const plotWidth = historyBottom || props.width <= 0 ? props.width : props.width - historyPx;
6868

6969
useEffect(() => {
7070
// Ensure the selected plot is visible. We do this so that the history
@@ -87,6 +87,11 @@ export const PlotsContainer = (props: PlotContainerProps) => {
8787
}, [plotHistoryRef]);
8888

8989
useEffect(() => {
90+
// Be defensive against null sizes when pane is invisible
91+
if (plotWidth <= 0 || plotHeight <= 0) {
92+
return;
93+
}
94+
9095
// Propagate current render settings. Use a debouncer to avoid excessive
9196
// messaging to language kernels.
9297
const debounceTimer = setTimeout(() => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const PositronPlots = (props: PropsWithChildren<PositronPlotsProps>) => {
135135
<ActionBars {...props} zoomHandler={zoomHandler} zoomLevel={zoom} />
136136
<PlotsContainer
137137
darkFilterMode={darkFilterMode}
138-
height={height - 34}
138+
height={height > 0 ? height - 34 : 0}
139139
positronPlotsService={props.positronPlotsService}
140140
showHistory={showHistory}
141141
visible={visible}

0 commit comments

Comments
 (0)