Skip to content

Commit 94afbc8

Browse files
committed
fix(#14112): changed from using setTimeout to requestAnimationFrame
1 parent 3942dbe commit 94afbc8

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

packages/runtime-dom/src/components/Transition.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,35 @@ function whenTransitionEnds(
378378
end()
379379
}
380380
}
381-
setTimeout(() => {
382-
if (ended < propCount) {
383-
end()
381+
// setTimeout(() => {
382+
// if (ended < propCount) {
383+
// end()
384+
// }
385+
// }, timeout + 1)
386+
387+
const fallbackTimeout = () => {
388+
let loopStart: number | null = null
389+
const loop = (timeStamp: number) => {
390+
if (!loopStart) {
391+
loopStart = timeStamp
392+
}
393+
394+
const elapsed = timeStamp - loopStart
395+
if (elapsed >= timeout + 1) {
396+
if (ended < propCount) {
397+
end()
398+
return
399+
}
400+
}
401+
402+
requestAnimationFrame(loop)
384403
}
385-
}, timeout + 1)
404+
405+
requestAnimationFrame(loop)
406+
}
407+
408+
fallbackTimeout()
409+
386410
el.addEventListener(endEvent, onEnd)
387411
}
388412

0 commit comments

Comments
 (0)