Only pop the pre-redirect controller when a redirect crosses contexts#251
Merged
Conversation
joemasilotti
approved these changes
Jul 6, 2026
joemasilotti
left a comment
Member
There was a problem hiding this comment.
Approved assuming this fixes #192!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Redirects were popping one view controller too many. This narrows the pop so it only fires when a redirect crosses the
default↔modalnavigation boundary — fixing the missing / incorrect back button in #190 while preserving the modal-redirect cleanup from #112.The bug (#190)
Since the 1.3.0 beta, following an internal redirect could leave the navigation stack wrong:
Works correctly in 1.2.x.
Root cause
session(_:didProposeVisit:)popped the top controller on every redirect (introduced in #160, generalizing the modal fix from #154 / #112):But Turbo already re-proposes a followed redirect with an
action: "replace"— it also doeshistory.replaceStateon the web side, so the redirect never becomes a history entry. Verified in the bundledturbo.min.js(Visit#followRedirect):So
route(proposal)on its own already replaces the pre-redirect controller in place (pushOrReplace→replaceLastViewController). The extra unconditionalpoptherefore removes a second controller — the screen underneath — which is exactly the lost / wrong back button in #190.The pop is only actually required when the redirect changes navigation context (
default↔modal): there the pre-redirect controller was pushed onto one stack whileroutetargets the other, leaving it orphaned (the original #112 problem).The fix
Pop only when the redirect crosses the context boundary:
replaceaction rewrites the pre-redirect controller in place. When the redirect targets the previous screen,pushOrReplace'svisitingPreviousPagebranch performs the animated back-pop — restoring the transition that went missing in the beta.Behavior
Relationship to #192
#192 also narrows the pop, but keys it off the session (
session === modalSession). Adefault → modalredirect is re-proposed by the main session (which performed the request), so #192 skips the pop there and re-introduces #112 — the pre-redirect controller is left orphaned beneath the presented modal. It also still double-popsmodal → modal. Keying off the context transition instead handles all four quadrants.Tests
Adds redirect coverage across the full
default/modalmatrix toNavigationHierarchyControllerTests, driven through the realSessionDelegateentry point (session(_:didProposeVisit:)) rather thanroute(_:).