mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Fix 8083 (#8105)
* override wrong positions in browser history * Lost events are taken into account during throttling
This commit is contained in:
parent
9dd09e2c6a
commit
0e0fa605d1
2 changed files with 18 additions and 2 deletions
5
.changeset/popular-planes-cover.md
Normal file
5
.changeset/popular-planes-cover.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
ViewTransition: bug fix for lost scroll position in browser history
|
|
@ -38,12 +38,21 @@ const { fallback = 'animate' } = Astro.props as Props;
|
||||||
|
|
||||||
const throttle = (cb: (...args: any[]) => any, delay: number) => {
|
const throttle = (cb: (...args: any[]) => any, delay: number) => {
|
||||||
let wait = false;
|
let wait = false;
|
||||||
|
// During the waiting time additional events are lost.
|
||||||
|
// So repeat the callback at the end if we have swallowed events.
|
||||||
|
let onceMore = false;
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
if (wait) return;
|
if (wait) {
|
||||||
|
onceMore = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
cb(...args);
|
cb(...args);
|
||||||
wait = true;
|
wait = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (onceMore) {
|
||||||
|
onceMore = false;
|
||||||
|
cb(...args);
|
||||||
|
}
|
||||||
wait = false;
|
wait = false;
|
||||||
}, delay);
|
}, delay);
|
||||||
};
|
};
|
||||||
|
@ -163,6 +172,8 @@ const { fallback = 'animate' } = Astro.props as Props;
|
||||||
}
|
}
|
||||||
if (state?.scrollY != null) {
|
if (state?.scrollY != null) {
|
||||||
scrollTo(0, state.scrollY);
|
scrollTo(0, state.scrollY);
|
||||||
|
// Overwrite erroneous updates by the scroll handler during transition
|
||||||
|
persistState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerEvent('astro:beforeload');
|
triggerEvent('astro:beforeload');
|
||||||
|
|
Loading…
Add table
Reference in a new issue