Skip to content

Commit

Permalink
only update our own history entires during back navigation through vi…
Browse files Browse the repository at this point in the history
…ew transitions (#8116)
  • Loading branch information
martrapp authored and ematipico committed Aug 21, 2023
1 parent a87cbe4 commit 33b8910
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-nails-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

On back navigation only animate view transitions that were animated going forward.
9 changes: 6 additions & 3 deletions packages/astro/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 });
}
Expand Down

0 comments on commit 33b8910

Please sign in to comment.