Skip to content

Commit bd8cafc

Browse files
committed
Fix hash link navigation issues with FF
Cleanup
1 parent 81af6ba commit bd8cafc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/kit/src/runtime/client/client.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,15 @@ export function create_client(app, target) {
15391539
// Removing the hash does a full page navigation in the browser, so make sure a hash is present
15401540
const [nonhash, hash] = url.href.split('#');
15411541
if (hash !== undefined && nonhash === location.href.split('#')[0]) {
1542+
// If we are trying to navigate to the same hash, we should only
1543+
// attempt to scroll to that element and avoid any history changes.
1544+
// Otherwise, this can cause Firefox to incorrectly assign a null
1545+
// history state value without any signal that we can detect.
1546+
if (current.url.hash === url.hash) {
1547+
event.preventDefault();
1548+
a.scrollIntoView();
1549+
return;
1550+
}
15421551
// set this flag to distinguish between navigations triggered by
15431552
// clicking a hash link and those triggered by popstate
15441553
hash_navigating = true;

0 commit comments

Comments
 (0)