From edcdd00d69529d8b1d689160813780e1d5f33f95 Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Mon, 13 May 2024 20:23:29 +0600 Subject: [PATCH] fix WKBackForwardListItem deallocated from background thread --- Sources/Navigation/NavigationAction.swift | 10 +--------- Sources/Navigation/NavigationType.swift | 18 +++++++++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Sources/Navigation/NavigationAction.swift b/Sources/Navigation/NavigationAction.swift index e0c985e8a..68b207057 100644 --- a/Sources/Navigation/NavigationAction.swift +++ b/Sources/Navigation/NavigationAction.swift @@ -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 ?? "")>" } } diff --git a/Sources/Navigation/NavigationType.swift b/Sources/Navigation/NavigationType.swift index a3b50eda6..fa83192d4 100644 --- a/Sources/Navigation/NavigationType.swift +++ b/Sources/Navigation/NavigationType.swift @@ -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) } }