Skip to content

Commit

Permalink
Generates missing popstate events for Firefox when navigating to hash…
Browse files Browse the repository at this point in the history
… targets on the same page. (#10679)
  • Loading branch information
martrapp authored Apr 4, 2024
1 parent d4b88c7 commit ca6bb1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/loud-numbers-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Generates missing popstate events for Firefox when navigating to hash targets on the same page.
7 changes: 6 additions & 1 deletion packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ const moveToLocation = (
history.scrollRestoration = 'auto';
const savedState = history.state;
location.href = to.href; // this kills the history state on Firefox
history.state || replaceState(savedState, ''); // this restores the history state
if (!history.state) {
replaceState(savedState, ''); // this restores the history state
if (intraPage){
window.dispatchEvent(new PopStateEvent('popstate' ));
}
}
} else {
if (!scrolledToTop) {
scrollTo({ left: 0, top: 0, behavior: 'instant' });
Expand Down

0 comments on commit ca6bb1f

Please sign in to comment.