Skip to content

Commit fa7f82c

Browse files
committed
Stabilize scrub callback during streaming updates
1 parent 86b5878 commit fa7f82c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libs/@hashintel/petrinaut/src/views/Editor/panels/BottomPanel/subviews/simulation-timeline.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,16 @@ const UPlotChart: React.FC<{
679679
const chartRef = useRef<uPlot | null>(null);
680680
const playheadFrameRef = useRef(currentFrameIndex);
681681
playheadFrameRef.current = currentFrameIndex;
682+
const totalFramesRef = useRef(totalFrames);
683+
totalFramesRef.current = totalFrames;
682684

683685
const onScrub = useCallback(
684686
(idx: number) => {
685-
setCurrentViewedFrame(Math.max(0, Math.min(idx, totalFrames - 1)));
687+
setCurrentViewedFrame(
688+
Math.max(0, Math.min(idx, totalFramesRef.current - 1)),
689+
);
686690
},
687-
[setCurrentViewedFrame, totalFrames],
691+
[setCurrentViewedFrame],
688692
);
689693

690694
// Build data from store

0 commit comments

Comments
 (0)