Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only update our own history entries during back navigation through VT #8116

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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