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

Stale content #184

Merged
merged 2 commits into from
Feb 28, 2024
Merged
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
20 changes: 20 additions & 0 deletions Source/Session/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Session: NSObject {
private lazy var bridge = WebViewBridge(webView: webView)
private var initialized = false
private var refreshing = false
private var isShowingStaleContent = false
private var isSnapshotCacheStale = false

/// Automatically creates a web view with the passed-in configuration
public convenience init(webViewConfiguration: WKWebViewConfiguration? = nil) {
Expand Down Expand Up @@ -91,6 +93,18 @@ public class Session: NSObject {
bridge.clearSnapshotCache()
}

// MARK: Caching

/// Clear the snapshot cache the next time the visitable view appears.
public func markSnapshotCacheAsStale() {
isSnapshotCacheStale = true
}

/// Reload the `Session` the next time the visitable view appears.
public func markContentAsStale() {
isShowingStaleContent = true
}

// MARK: Visitable activation

private var activatedVisitable: Visitable?
Expand Down Expand Up @@ -228,6 +242,12 @@ extension Session: VisitableDelegate {
} else if visitable !== topmostVisit.visitable {
// Navigating backward
visit(visitable, action: .restore)
} else if isShowingStaleContent {
reload()
isShowingStaleContent = false
} else if isSnapshotCacheStale {
clearSnapshotCache()
isSnapshotCacheStale = false
Comment on lines 242 to +250
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to work on the Hiking Journal demo.
The condition on L242 is different than in #173 (comment).
Why are not the flags evaluated separately after the guard statement?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I just confirmed this PR doesn't actually fix the core issue.

I just opened #185 - thanks!

}
}

Expand Down