Skip to content

Commit e6ef21a

Browse files
committed
[fix] Reset navigating store upon return to site with a bfcache hit
Fixes #5415 The alternative fix would have been to do this in beforeunload, but this might result in more possibilities of flickering than the other way around.
1 parent 9766b9f commit e6ef21a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/tough-dolls-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Reset navigating store upon return to site with a bfcache hit

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,16 @@ export function create_client({ target, session, base, trailing_slash }) {
12191219
);
12201220
}
12211221
});
1222+
1223+
addEventListener('pageshow', (event) => {
1224+
// If the user navigates to another site and then uses the back button and
1225+
// bfcache hits, we need to set navigating to null, the site doesn't know
1226+
// the navigation away from it was successful.
1227+
// Info about bfcache here: https://web.dev/bfcache
1228+
if (event.persisted) {
1229+
stores.navigating.set(null);
1230+
}
1231+
});
12221232
},
12231233

12241234
_hydrate: async ({ status, error, nodes, params, routeId }) => {

0 commit comments

Comments
 (0)