diff options
author | 2023-08-16 22:38:18 +0200 | |
---|---|---|
committer | 2023-08-16 16:38:18 -0400 | |
commit | 0e0fa605d109cc91e08a1ae1cc560ea240fe631b (patch) | |
tree | 3f4801702a91e9670a9bd1041c8d06e9fa07409d | |
parent | 9dd09e2c6ae6d7d453990a5401054e3dc642c458 (diff) | |
download | astro-0e0fa605d109cc91e08a1ae1cc560ea240fe631b.tar.gz astro-0e0fa605d109cc91e08a1ae1cc560ea240fe631b.tar.zst astro-0e0fa605d109cc91e08a1ae1cc560ea240fe631b.zip |
Fix 8083 (#8105)
* override wrong positions in browser history
* Lost events are taken into account during throttling
Diffstat (limited to '')
-rw-r--r-- | .changeset/popular-planes-cover.md | 5 | ||||
-rw-r--r-- | packages/astro/components/ViewTransitions.astro | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/.changeset/popular-planes-cover.md b/.changeset/popular-planes-cover.md new file mode 100644 index 000000000..c379a7edc --- /dev/null +++ b/.changeset/popular-planes-cover.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +ViewTransition: bug fix for lost scroll position in browser history diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 28a17a09d..47eb3c112 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -38,12 +38,21 @@ const { fallback = 'animate' } = Astro.props as Props; const throttle = (cb: (...args: any[]) => any, delay: number) => { 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[]) => { - if (wait) return; - + if (wait) { + onceMore = true; + return; + } cb(...args); wait = true; setTimeout(() => { + if (onceMore) { + onceMore = false; + cb(...args); + } wait = false; }, delay); }; @@ -163,6 +172,8 @@ const { fallback = 'animate' } = Astro.props as Props; } if (state?.scrollY != null) { scrollTo(0, state.scrollY); + // Overwrite erroneous updates by the scroll handler during transition + persistState(state); } triggerEvent('astro:beforeload'); |