Skip to content

Commit 33b8910

Browse files
martrappematipico
authored andcommitted
only update our own history entires during back navigation through view transitions (#8116)
1 parent a87cbe4 commit 33b8910

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

.changeset/small-nails-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
On back navigation only animate view transitions that were animated going forward.

packages/astro/components/ViewTransitions.astro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,11 @@ const { fallback = 'animate' } = Astro.props as Props;
306306
return;
307307
}
308308

309-
// hash change creates no state.
309+
// History entries without state are created by the browser (e.g. for hash links)
310+
// Our view transition entries always have state.
311+
// Just ignore stateless entries.
312+
// The browser will handle navigation fine without our help
310313
if (ev.state === null) {
311-
persistState({ index: currentHistoryIndex, scrollY });
312-
ev.preventDefault();
313314
return;
314315
}
315316

@@ -344,6 +345,8 @@ const { fallback = 'animate' } = Astro.props as Props;
344345
addEventListener(
345346
'scroll',
346347
throttle(() => {
348+
// only updste history entries that are managed by us
349+
// leave other entries alone and do not accidently add state.
347350
if (history.state) {
348351
persistState({ ...history.state, scrollY });
349352
}

0 commit comments

Comments
 (0)