summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Martin Trapp <94928215+martrapp@users.noreply.github.com> 2023-11-23 19:08:37 +0100
committerGravatar GitHub <noreply@github.com> 2023-11-23 19:08:37 +0100
commit607542c7cf9fe9813c06f1d96615d6c793262d22 (patch)
tree5132b9a94f88ab918600bdafb8738162ab2fac32
parent04fdc1c613171409ed1a2bd887326e26cdb8b5ef (diff)
downloadastro-607542c7cf9fe9813c06f1d96615d6c793262d22.tar.gz
astro-607542c7cf9fe9813c06f1d96615d6c793262d22.tar.zst
astro-607542c7cf9fe9813c06f1d96615d6c793262d22.zip
fix scroll restoration issue on webKit browsers (#9186)
* 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 <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
-rw-r--r--.changeset/shaggy-socks-glow.md5
-rw-r--r--packages/astro/src/transitions/router.ts3
2 files changed, 7 insertions, 1 deletions
diff --git a/.changeset/shaggy-socks-glow.md b/.changeset/shaggy-socks-glow.md
new file mode 100644
index 000000000..409d02908
--- /dev/null
+++ b/.changeset/shaggy-socks-glow.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes a view transition issue on webKit browsers that prevented scrolling to #fragments
diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts
index a97abfcf7..6ff0efc01 100644
--- a/packages/astro/src/transitions/router.ts
+++ b/packages/astro/src/transitions/router.ts
@@ -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)
@@ -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';
}
};