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

Conversation

pfeiffer
Copy link
Contributor

Fixes #175, #136 and #160.

Building on the change in #160 by @afcapel, this tracks if a visit is a page refresh and skips showing screenshot and activity spinners. The WebView is still activated and can be scrolled during the refresh visits as expected.

Previously the WebView would be 'blanked', become unresponsive and spinners would be shown.

The behavior during refreshes after this change (no spinners or blank webview and the view is still scrollable and active):

MorphAfter.mov

Copy link
Collaborator

@jayohms jayohms left a comment

Choose a reason for hiding this comment

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

Thank you @pfeiffer! This looks like a straightforward, elegant solution. I left some comments for improvements that we'll need before merging. If you're able to get to it soon, that'd be awesome — otherwise I can propose another PR with the corresponding changes.

@@ -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.

@@ -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

@@ -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 👏

Comment on lines 103 to +106
if (Turbo.navigator.locationWithActionIsSamePage(location, options.action)) {
Turbo.navigator.view.scrollToAnchorFromLocation(location)
return
} else if (this.currentVisit?.location?.href === location.href) {
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.

@jayohms
Copy link
Collaborator

jayohms commented Feb 23, 2024

Closed in favor of #178

@jayohms jayohms closed this Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Turbo 8 morphing refreshes not supported?
2 participants