Skip to content

Commit

Permalink
fix scroll restoration issue on webKit browsers (#9186)
Browse files Browse the repository at this point in the history
* fix scroll restoration issue on webKit browsers

* add changeset

* Update .changeset/shaggy-socks-glow.md

* Update .changeset/shaggy-socks-glow.md

Co-authored-by: Sarah Rainsberger <[email protected]>

---------

Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
martrapp and sarah11918 authored Nov 23, 2023
1 parent 04fdc1c commit 607542c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shaggy-socks-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a view transition issue on webKit browsers that prevented scrolling to #fragments
3 changes: 2 additions & 1 deletion packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ const moveToLocation = (to: URL, from: URL, options: Options, historyState?: Sta
to.href
);
}
history.scrollRestoration = 'manual';
}
// now we are on the new page for non-history navigations!
// (with history navigation page change happens before popstate is fired)
Expand All @@ -213,12 +212,14 @@ const moveToLocation = (to: URL, from: URL, options: Options, historyState?: Sta
// because we are already on the target page ...
// ... what comes next is a intra-page navigation
// that won't reload the page but instead scroll to the fragment
history.scrollRestoration = 'auto';
location.href = to.href;
} else {
if (!scrolledToTop) {
scrollTo({ left: 0, top: 0, behavior: 'instant' });
}
}
history.scrollRestoration = 'manual';
}
};

Expand Down

0 comments on commit 607542c

Please sign in to comment.