Skip to content

Commit

Permalink
fix WKBackForwardListItem deallocated from background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed May 13, 2024
1 parent 72be4e7 commit edcdd00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
10 changes: 1 addition & 9 deletions Sources/Navigation/NavigationAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,6 @@ extension NavigationPreferences: CustomDebugStringConvertible {

extension HistoryItemIdentity: CustomDebugStringConvertible {
public var debugDescription: String {
"\(object)".replacingOccurrences(of: "WKBackForwardListItem: ", with: "").dropping(suffix: ">")
+ {
guard let backForwardListItem = object as? WKBackForwardListItem else { return "" }
var url = " " + backForwardListItem.url.absoluteString
if backForwardListItem.initialURL != backForwardListItem.url {
url += " (initial: \(backForwardListItem.initialURL.absoluteString))"
}
return url
}() + ">"
"<\(identifier) url: \(url?.absoluteString ?? "") title: \(title ?? "<nil>")>"
}
}
18 changes: 11 additions & 7 deletions Sources/Navigation/NavigationType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,29 @@ public protocol WebViewNavigationAction {
var isUserInitiated: Bool? { get }
}

public struct HistoryItemIdentity: Hashable {
let object: any AnyObject & Hashable
public class HistoryItemIdentity: Hashable {
let identifier: ObjectIdentifier
let title: String?
let url: URL?

public init(_ object: any AnyObject & Hashable) {
self.object = object
public init(backForwardListItem: WKBackForwardListItem) {
self.identifier = ObjectIdentifier(backForwardListItem)
self.title = backForwardListItem.title
self.url = backForwardListItem.url
}

public static func == (lhs: HistoryItemIdentity, rhs: HistoryItemIdentity) -> Bool {
lhs.object === rhs.object
lhs.identifier == rhs.identifier
}

public func hash(into hasher: inout Hasher) {
hasher.combine(object)
hasher.combine(identifier)
}
}

extension WKBackForwardListItem {

public var identity: HistoryItemIdentity { HistoryItemIdentity(self) }
public var identity: HistoryItemIdentity { HistoryItemIdentity(backForwardListItem: self) }

}

Expand Down

0 comments on commit edcdd00

Please sign in to comment.