Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not show spinners or screenshots during refresh visits #177

Closed
Closed
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
4 changes: 4 additions & 0 deletions Source/Session/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,16 @@ extension Session: VisitDelegate {
}

func visitWillStart(_ visit: Visit) {
guard !visit.isPageRefresh else { return }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 👏


visit.visitable.showVisitableScreenshot()
activateVisitable(visit.visitable)
}

func visitDidStart(_ visit: Visit) {
guard !visit.hasCachedSnapshot else { return }
guard !visit.isPageRefresh else { return }

visit.visitable.showVisitableActivityIndicator()
}

Expand Down
5 changes: 3 additions & 2 deletions Source/Visit/JavaScriptVisit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ final class JavaScriptVisit: Visit {
}

extension JavaScriptVisit: WebViewVisitDelegate {
func webView(_ webView: WebViewBridge, didStartVisitWithIdentifier identifier: String, hasCachedSnapshot: Bool) {
log("didStartVisitWithIdentifier", ["identifier": identifier, "hasCachedSnapshot": hasCachedSnapshot])
func webView(_ webView: WebViewBridge, didStartVisitWithIdentifier identifier: String, hasCachedSnapshot: Bool, isPageRefresh: Bool) {
log("didStartVisitWithIdentifier", ["identifier": identifier, "hasCachedSnapshot": hasCachedSnapshot, "isPageRefresh": isPageRefresh])
self.identifier = identifier
self.hasCachedSnapshot = hasCachedSnapshot
self.isPageRefresh = isPageRefresh

delegate?.visitDidStart(self)
}
Expand Down
1 change: 1 addition & 0 deletions Source/Visit/Visit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Visit: NSObject {
let location: URL

var hasCachedSnapshot: Bool = false
var isPageRefresh: Bool = false
private(set) var state: VisitState

init(visitable: Visitable, options: VisitOptions, bridge: WebViewBridge) {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebView/WebViewBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol WebViewPageLoadDelegate: AnyObject {
}

protocol WebViewVisitDelegate: AnyObject {
func webView(_ webView: WebViewBridge, didStartVisitWithIdentifier identifier: String, hasCachedSnapshot: Bool)
func webView(_ webView: WebViewBridge, didStartVisitWithIdentifier identifier: String, hasCachedSnapshot: Bool, isPageRefresh: Bool)
func webView(_ webView: WebViewBridge, didStartRequestForVisitWithIdentifier identifier: String, date: Date)
func webView(_ webView: WebViewBridge, didCompleteRequestForVisitWithIdentifier identifier: String)
func webView(_ webView: WebViewBridge, didFailRequestForVisitWithIdentifier identifier: String, statusCode: Int)
Expand Down Expand Up @@ -126,7 +126,7 @@ extension WebViewBridge: ScriptMessageHandlerDelegate {
case .visitProposed:
delegate?.webView(self, didProposeVisitToLocation: message.location!, options: message.options!)
case .visitStarted:
visitDelegate?.webView(self, didStartVisitWithIdentifier: message.identifier!, hasCachedSnapshot: message.data["hasCachedSnapshot"] as! Bool)
visitDelegate?.webView(self, didStartVisitWithIdentifier: message.identifier!, hasCachedSnapshot: message.data["hasCachedSnapshot"] as! Bool, isPageRefresh: message.data["isPageRefresh"] as! Bool)
case .visitRequestStarted:
visitDelegate?.webView(self, didStartRequestForVisitWithIdentifier: message.identifier!, date: message.date)
case .visitRequestCompleted:
Expand Down
5 changes: 4 additions & 1 deletion Source/WebView/turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
if (Turbo.navigator.locationWithActionIsSamePage(location, options.action)) {
Turbo.navigator.view.scrollToAnchorFromLocation(location)
return
} else if (this.currentVisit?.location?.href === location.href) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the corresponding Android PR, I found that the approach doesn't work immediately after a page cold boot, because this.currentVisit hasn't been set yet. Using Turbo.navigator.location?.href === location.href works in all circumstances, though. https://github.com/hotwired/turbo-android/pull/292/files#diff-aafcc0efe91961803491a50ad6158bc1b6416c69417325a6fa5d1bc50a2be45cR105

Comment on lines 103 to +106
Copy link
Collaborator

@jayohms jayohms Feb 22, 2024

Choose a reason for hiding this comment

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

I'd prefer that we changed the conditional logic to look like the modified Android adapter logic with comments and logging: https://github.com/hotwired/turbo-android/pull/292/files#diff-aafcc0efe91961803491a50ad6158bc1b6416c69417325a6fa5d1bc50a2be45cL101-L108

It's more clear and removes a conditional that was necessary during a transitional Turbo 7 rollout period.

this.visitLocationWithOptionsAndRestorationIdentifier(location, options, Turbo.navigator.restorationIdentifier)
return
}
}

Expand All @@ -116,7 +119,7 @@

visitStarted(visit) {
this.currentVisit = visit
this.postMessage("visitStarted", { identifier: visit.identifier, hasCachedSnapshot: visit.hasCachedSnapshot() })
this.postMessage("visitStarted", { identifier: visit.identifier, hasCachedSnapshot: visit.hasCachedSnapshot(), isPageRefresh: visit.isPageRefresh })
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't look compatible with Turbo 7 without page refresh support. The mobile adapters need to remain compatible with Turbolinks 5, Turbo 7, and Turbo 8.

this.issueRequestForVisitWithIdentifier(visit.identifier)
this.changeHistoryForVisitWithIdentifier(visit.identifier)
this.loadCachedSnapshotForVisitWithIdentifier(visit.identifier)
Expand Down