mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -05:00
only update our own history entires during back navigation through view transitions (#8116)
This commit is contained in:
parent
da6e3da1ce
commit
b290f0a997
2 changed files with 11 additions and 3 deletions
5
.changeset/small-nails-try.md
Normal file
5
.changeset/small-nails-try.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
On back navigation only animate view transitions that were animated going forward.
|
|
@ -306,10 +306,11 @@ const { fallback = 'animate' } = Astro.props as Props;
|
||||||
return;
|
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) {
|
if (ev.state === null) {
|
||||||
persistState({ index: currentHistoryIndex, scrollY });
|
|
||||||
ev.preventDefault();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +345,8 @@ const { fallback = 'animate' } = Astro.props as Props;
|
||||||
addEventListener(
|
addEventListener(
|
||||||
'scroll',
|
'scroll',
|
||||||
throttle(() => {
|
throttle(() => {
|
||||||
|
// only updste history entries that are managed by us
|
||||||
|
// leave other entries alone and do not accidently add state.
|
||||||
if (history.state) {
|
if (history.state) {
|
||||||
persistState({ ...history.state, scrollY });
|
persistState({ ...history.state, scrollY });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue