Skip to content

Commit

Permalink
Merge pull request #60 from hotwired/double-visit-fix
Browse files Browse the repository at this point in the history
Fix double-visits after modal form submission redirects
  • Loading branch information
jayohms authored Dec 17, 2024
2 parents 21313e4 + fc93999 commit 3cea3b0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Source/Turbo/Session/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,15 @@ extension Session: VisitableDelegate {
}

// Navigating forward - complete navigation early.
if visitable === currentVisit.visitable && currentVisit.state == .started {
completeNavigationForCurrentVisit()
return
if visitable === currentVisit.visitable {
let currentVisitHasResponse = currentVisit.options.response?.responseHTML != nil

/// Most visits will be `.started` here, but form submission redirects containing `response.responseHTML` in
/// the modal context while navigating back to the default context will already be `.completed` at this point.
if currentVisit.state == .started || (currentVisitHasResponse && currentVisit.state == .completed) {
completeNavigationForCurrentVisit()
return
}
}

// Navigating backward from a web view screen to a web view screen.
Expand Down

0 comments on commit 3cea3b0

Please sign in to comment.