Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bifrost/lib/turbolinks/visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class Visit {
const url = new URL(this.location.toString(), this.location.getOrigin());
navigate(url.pathname + url.hash + url.search, {
overwriteLastHistoryEntry: this.action === "replace",
pageContext: { _turbolinksVisit: this },
}).catch(console.error);
this.progress = 0;
this.requestInFlight = true;
Expand Down
2 changes: 1 addition & 1 deletion bifrost/renderer/onBeforeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const onBeforeRoute = (pageContext: PageContext) => {
if (typeof window !== "undefined" && pageContext.isClientSide) {
const Turbolinks = window.Turbolinks;

let currentVisit = Turbolinks.controller.currentVisit;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Vike does any async between our call to navigate() above and executing onBeforeRoute hook, then it is possible to grab the wrong visit here.

This PR fixes that.

let currentVisit = pageContext._turbolinksVisit;

if (pageContext.isHistoryNavigation) {
const snapshot = Turbolinks.controller.getCachedSnapshotForLocation(
Expand Down