Keep the article web view alive while it's in element fullscreen, so deallocating it mid-transition can't trigger the WebKit crash in WebFullScreenManagerProxy. Fixes #5382.

This commit is contained in:
Brent Simmons committed 2026-08-10 09:36:14 -07:00
1 parent 5e60e8bb19
commit d7f1d1694c
2 files changed
+46

No files matched your search

+9
View File
@@ -13,6 +13,7 @@ final class PreloadedWebView: WKWebView {
private var isReady: Bool = false
private var readyCompletion: (() -> Void)?
private var fullscreenStateObservation: NSKeyValueObservation?
init(articleIconSchemeHandler: ArticleIconSchemeHandler) {
let configuration = WebViewConfiguration.configuration(with: articleIconSchemeHandler)
@@ -22,6 +23,14 @@ final class PreloadedWebView: WKWebView {
self?.userDefaultsDidChange()
}
}
fullscreenStateObservation = observe(\.fullscreenState, options: []) { [weak self] _, _ in
Task { @MainActor in
guard let self else {
return
}
WebViewFullscreenKeeper.shared.updateRetention(for: self)
}
}
}
required init?(coder: NSCoder) {
+37
View File
@@ -0,0 +1,37 @@
//
// WebViewFullscreenKeeper.swift
// NetNewsWire-iOS
//
// Created by Brent Simmons on 8/10/26.
// Copyright © 2026 Ranchero Software. All rights reserved.
//
import UIKit
import WebKit
import os
/// Keeps a web view alive while it's in any element-fullscreen state.
/// Deallocating a web view during the enter-fullscreen transition triggers
/// a WebKit RELEASE_ASSERT in WebFullScreenManagerProxy.
/// <https://github.com/Ranchero-Software/NetNewsWire/issues/5382>
@MainActor final class WebViewFullscreenKeeper {
static let shared = WebViewFullscreenKeeper()
private var retainedWebViews = [ObjectIdentifier: WKWebView]()
private static let logger = Logger(subsystem: Logger.nnwSubsystem, category: "WebViewFullscreenKeeper")
func updateRetention(for webView: WKWebView) {
let identifier = ObjectIdentifier(webView)
let countBefore = retainedWebViews.count
if webView.fullscreenState == .notInFullscreen {
retainedWebViews.removeValue(forKey: identifier)
} else {
retainedWebViews.updateValue(webView, forKey: identifier)
}
Self.logger.debug("WebViewFullscreenKeeper: updateRetention — fullscreenState \(String(describing: webView.fullscreenState)), retainedWebViews count before \(countBefore) and after \(self.retainedWebViews.count)")
}
}