Only reload the WebView on a cold boot visit when it's already on the visit location - #207
Merged
Conversation
… visit location When a form submission inside a modal screen redirects to /refresh_historical_location, the modal is dismissed and the underlying screen is refreshed via a visit with reload: true. That reload races with the underlying screen's restore visit: when the reload runs first, the WebView's current page is still the dismissed modal's page, so WebView.reload() renders the modal's page on the underlying screen instead of its own location. Reload only when the WebView is already on the visit location, otherwise load the visit location directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Symptoms
When a form inside a
modalcontext screen is submitted and the server responds withrefresh_or_redirect_to(a redirect to/refresh_historical_location), the modal is dismissed — but intermittently the screen behind it ends up rendering the modal's page instead of its own. For example, posting a comment from a modal composer screen sometimes leaves the underlying screen showing a fresh, empty composer form (with the underlying screen's toolbar), even though the comment was created successfully. Navigating back reveals the parent page with the submitted content.Root cause
Dismissing a modal with a
REFRESHmodal result triggers two concurrent operations on the shared WebView from the underlying destination'sonStartAfterModalResult:HotwireWebFragmentDelegate.onStartAfterModalResult()→initNavigationVisit()→ aRESTOREvisit to the destination's location (turbo.js updates the WebView's history asynchronously), andHotwireFragmentDelegate.onStartAfterModalResult()→ routes the modal result →NavigatorMode.REFRESH→refresh()→session.reset()+ a cold boot visit withreload: true, which callsWebView.reload()inSession.visitLocationAsColdBoot().These race. When the cold boot runs before the restore visit has changed the WebView's history, the WebView's current page is still the dismissed modal's page — so
WebView.reload()re-loads the modal's URL instead of the destination's location. The session then treats the cold boot as completed for the destination's location while the WebView actually renders the modal's page.Debug log from a failing run (message screen behind a dismissed comment composer modal):
Fix
WebView.reload()exists to handle same-page visits for URLs with anchors (see the comment above the change). That only applies when the WebView is already on the visit location. Guard thereload()call accordingly and load the visit location directly otherwise:Testing
onPageStartedreports the underlying screen's URL) and the modal flow behaves correctly — modal closes, underlying screen refreshes with the submitted content. Exercised repeatedly via modal form submissions ending inrefresh_or_redirect_to.🤖 Generated with Claude Code