Skip to content

Commit c80424b

Browse files
committed
Lost events are taken into account during throttling
1 parent c808666 commit c80424b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/astro/components/ViewTransitions.astro

+11-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ const { fallback = 'animate' } = Astro.props as Props;
3838

3939
const throttle = (cb: (...args: any[]) => any, delay: number) => {
4040
let wait = false;
41+
// During the waiting time additional events are lost.
42+
// So repeat the callback at the end if we have swallowed events.
43+
let onceMore = false;
4144
return (...args: any[]) => {
42-
if (wait) return;
43-
45+
if (wait) {
46+
onceMore = true;
47+
return;
48+
}
4449
cb(...args);
4550
wait = true;
4651
setTimeout(() => {
52+
if (onceMore) {
53+
onceMore = false;
54+
cb(...args);
55+
}
4756
wait = false;
4857
}, delay);
4958
};

0 commit comments

Comments
 (0)