Skip to content

Commit eca15b0

Browse files
committed
fix: cleanup pendingFirstStagetimeout
1 parent 0fd7e67 commit eca15b0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/webui/src/client/lib/viewPort.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,19 @@ function getElementToScrollTo(
190190
return elementToScrollToOrSegmentId
191191
}
192192

193+
let pendingFirstStageTimeout: NodeJS.Timeout | undefined
194+
193195
async function innerScrollToSegment(
194196
elementToScrollTo: HTMLElement,
195197
forceScroll?: boolean,
196198
noAnimation?: boolean,
197199
secondStage?: boolean
198200
): Promise<boolean> {
199201
if (!secondStage) {
202+
if (pendingFirstStageTimeout) {
203+
clearTimeout(pendingFirstStageTimeout)
204+
pendingFirstStageTimeout = undefined
205+
}
200206
currentScrollingElement = elementToScrollTo
201207
} else if (secondStage && elementToScrollTo !== currentScrollingElement) {
202208
throw new Error('Scroll overriden by another scroll')
@@ -223,7 +229,8 @@ async function innerScrollToSegment(
223229
return new Promise<boolean>((resolve, reject) => {
224230
if (!secondStage) {
225231
// Wait to settle 1 atemt to scroll
226-
setTimeout(() => {
232+
pendingFirstStageTimeout = setTimeout(() => {
233+
pendingFirstStageTimeout = undefined
227234
let { top, bottom } = elementToScrollTo.getBoundingClientRect()
228235
top = Math.floor(top)
229236
bottom = Math.floor(bottom)

0 commit comments

Comments
 (0)