diff options
author | 2023-08-17 18:18:30 +0200 | |
---|---|---|
committer | 2023-08-21 14:16:36 +0100 | |
commit | 33b8910cfdce5713891c50a84a0a8fe926311710 (patch) | |
tree | ed19452e0b29deb4a6792e9701bbbcdc95ccac25 | |
parent | a87cbe400314341d5f72abf86ea264e6b47c091f (diff) | |
download | astro-33b8910cfdce5713891c50a84a0a8fe926311710.tar.gz astro-33b8910cfdce5713891c50a84a0a8fe926311710.tar.zst astro-33b8910cfdce5713891c50a84a0a8fe926311710.zip |
only update our own history entires during back navigation through view transitions (#8116)
-rw-r--r-- | .changeset/small-nails-try.md | 5 | ||||
-rw-r--r-- | packages/astro/components/ViewTransitions.astro | 9 |
2 files changed, 11 insertions, 3 deletions
diff --git a/.changeset/small-nails-try.md b/.changeset/small-nails-try.md new file mode 100644 index 000000000..3f6f591f1 --- /dev/null +++ b/.changeset/small-nails-try.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +On back navigation only animate view transitions that were animated going forward. diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 3967d0aee..4b7a46551 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -306,10 +306,11 @@ const { fallback = 'animate' } = Astro.props as Props; return; } - // hash change creates no state. + // History entries without state are created by the browser (e.g. for hash links) + // Our view transition entries always have state. + // Just ignore stateless entries. + // The browser will handle navigation fine without our help if (ev.state === null) { - persistState({ index: currentHistoryIndex, scrollY }); - ev.preventDefault(); return; } @@ -344,6 +345,8 @@ const { fallback = 'animate' } = Astro.props as Props; addEventListener( 'scroll', throttle(() => { + // only updste history entries that are managed by us + // leave other entries alone and do not accidently add state. if (history.state) { persistState({ ...history.state, scrollY }); } |