From cc19be05a6279dbcad2de6cc0d4bba63bcf3378d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 2 Aug 2026 22:32:08 -0700 Subject: [PATCH 1/6] Skip the home-page icon fallback while a feed's declared icon is still downloading. Fixes #5376. --- .../Sources/Images/FeedIconDownloader.swift | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Modules/Images/Sources/Images/FeedIconDownloader.swift b/Modules/Images/Sources/Images/FeedIconDownloader.swift index 74685f0c1..7b244dceb 100644 --- a/Modules/Images/Sources/Images/FeedIconDownloader.swift +++ b/Modules/Images/Sources/Images/FeedIconDownloader.swift @@ -75,7 +75,7 @@ extension Notification.Name { @MainActor func checkFeedIconURL() { if let iconURL = feed.iconURL, !Self.shouldIgnoreFeedIconURL(feed) { - icon(forURL: iconURL, feed: feed) { (image) in + icon(forURL: iconURL, feed: feed) { (image, isDefinitive) in Task { @MainActor in if self.cache[feed] != nil { return // already cached @@ -84,7 +84,10 @@ extension Notification.Name { self.cache[feed] = IconImage(image) self.cacheIconURLForFeedURL(iconURL: iconURL, feedURL: feed.url) self.postFeedIconDidBecomeAvailableNotification(feed) - } else { + } else if isDefinitive { + // The declared icon failed or isn’t an image. A still-downloading + // icon is no reason to fall back to the home page’s icon. + // checkHomePageURL() } } @@ -95,7 +98,7 @@ extension Notification.Name { } if let previouslyFoundIconURL = ImageMetadataDatabase.shared.iconURL(forFeedURL: feed.url) { - icon(forURL: previouslyFoundIconURL, feed: feed) { image in + icon(forURL: previouslyFoundIconURL, feed: feed) { image, _ in MainActor.assumeIsolated { if self.cache[feed] != nil { return // already cached @@ -206,7 +209,7 @@ private extension FeedIconDownloader { if let url = metadata.bestWebsiteIconURL() { homePagesWithNoIconURL.remove(homePageURL) - icon(forURL: url, feed: feed) { image in + icon(forURL: url, feed: feed) { image, _ in Task { @MainActor in resultBlock(image, url) } @@ -218,18 +221,28 @@ private extension FeedIconDownloader { resultBlock(nil, nil) } - func icon(forURL url: String, feed: Feed, _ imageResultBlock: @escaping ImageResultBlock) { + /// `isDefinitive` is false when the image is still downloading — imageDidBecomeAvailable + /// re-runs icon(for:) when it arrives. + func icon(forURL url: String, feed: Feed, _ imageResultBlock: @escaping @MainActor (RSImage?, _ isDefinitive: Bool) -> Void) { let url = Self.sanitizedIconURL(url) let kind = ActivityKind.downloadFeedImage(feedURL: url) if let imageData = imageDownloader.image(for: url, activityOwner: .feedImageDownloader, activityKind: kind, activityDetail: feed.nameForDisplay) { - RSImage.image(with: imageData, imageResultBlock: imageResultBlock) + RSImage.image(with: imageData) { image in + imageResultBlock(image, true) + } + return + } + + let urlIsUnfetchable = !url.hasPrefix("http://") && !url.hasPrefix("https://") + if urlIsUnfetchable || ImageMetadataDatabase.shared.recentlyFailed(url: url) { + imageResultBlock(nil, true) return } waitingForFeedURLs[url, default: Set()].insert(feed) - imageResultBlock(nil) + imageResultBlock(nil, false) } func postFeedIconDidBecomeAvailableNotification(_ feed: Feed) { From a2b1ea7e5e53c0d38f318e5774467f896ad27207 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 2 Aug 2026 22:34:17 -0700 Subject: [PATCH 2/6] Prefer a feed's declared icon over a previously discovered home-page icon. Fixes #5376. --- .../Sources/Images/FeedIconDownloader.swift | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Modules/Images/Sources/Images/FeedIconDownloader.swift b/Modules/Images/Sources/Images/FeedIconDownloader.swift index 7b244dceb..ee2a42dac 100644 --- a/Modules/Images/Sources/Images/FeedIconDownloader.swift +++ b/Modules/Images/Sources/Images/FeedIconDownloader.swift @@ -97,16 +97,19 @@ extension Notification.Name { } } - if let previouslyFoundIconURL = ImageMetadataDatabase.shared.iconURL(forFeedURL: feed.url) { + // The stored icon URL remembers an icon discovered via the home page. A feed + // that declares its own icon supersedes it. + // + let feedDeclaresIconURL = feed.iconURL != nil && !Self.shouldIgnoreFeedIconURL(feed) + + if !feedDeclaresIconURL, let previouslyFoundIconURL = ImageMetadataDatabase.shared.iconURL(forFeedURL: feed.url) { icon(forURL: previouslyFoundIconURL, feed: feed) { image, _ in - MainActor.assumeIsolated { - if self.cache[feed] != nil { - return // already cached - } - if let image { - self.cache[feed] = IconImage(image) - self.postFeedIconDidBecomeAvailableNotification(feed) - } + if self.cache[feed] != nil { + return // already cached + } + if let image { + self.cache[feed] = IconImage(image) + self.postFeedIconDidBecomeAvailableNotification(feed) } } From 5a488866e755f2e703b14c610242d0d48165812d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 2 Aug 2026 22:39:51 -0700 Subject: [PATCH 3/6] Consult the icon downloaders ahead of the session cache so a newly arrived feed icon replaces a stale one. Fixes #5376. --- Shared/IconImageCache.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Shared/IconImageCache.swift b/Shared/IconImageCache.swift index 3ceb0d83d..a7c93c16e 100644 --- a/Shared/IconImageCache.swift +++ b/Shared/IconImageCache.swift @@ -133,20 +133,25 @@ private extension IconImageCache { if Self.isNetNewsWireBrandedFeed(feed) { return IconImage.nnwFeedIcon } - if let iconImage = feedIconImageCache[feedID] { - return iconImage - } + + // The downloaders are the source of truth — consult them ahead of the local + // dictionaries so a newly arrived icon replaces a stale one. The dictionaries + // keep the last known icons across the downloaders’ low-memory and background flushes. + // if let iconImage = FeedIconDownloader.shared.cachedIcon(for: feed) { feedIconImageCache[feedID] = iconImage return iconImage } - if let faviconImage = faviconImageCache[feedID] { - return faviconImage + if let iconImage = feedIconImageCache[feedID] { + return iconImage } if let faviconImage = FaviconDownloader.shared.cachedFaviconAsIcon(for: feed) { faviconImageCache[feedID] = faviconImage return faviconImage } + if let faviconImage = faviconImageCache[feedID] { + return faviconImage + } return nil } From 4021fb3639deb571d73b7c604647af590b792e65 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 09:27:27 -0700 Subject: [PATCH 4/6] Fix bug where reader view articles could open scrolled to the middle instead of the top. Fixes #5243. --- iOS/Article/ArticleViewController.swift | 6 ++++++ iOS/Article/WebViewController.swift | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index fe306b3d3..db4573ba7 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -61,6 +61,12 @@ final class ArticleViewController: UIViewController { didSet { Self.logger.debug("ArticleViewController: article didSet: \(self.article?.accountID ?? "nil") \(self.article?.articleID ?? "nil") \(self.article?.title ?? "nil")") + if oldValue != article { + // The launch-restoration scroll position belongs only to the restored article. + // + restoreScrollPosition = nil + } + if let controller = currentWebViewController, controller.article != article { controller.setArticle(article) if isPageTransitionInProgress { diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index a9457e6cf..625d54b43 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -156,6 +156,9 @@ final class WebViewController: UIViewController { if article != self.article { self.article = article + // A restoration offset belongs only to the article it was saved for. + // + restoreWindowScrollY = nil if updateView { if article?.feed?.readerViewAlwaysEnabled == true { startArticleExtractor() @@ -343,6 +346,7 @@ extension WebViewController: ArticleExtractorDelegate { self.extractedArticle = extractedArticle if let restoreWindowScrollY = restoreWindowScrollY { windowScrollY = restoreWindowScrollY + self.restoreWindowScrollY = nil } isShowingExtractedArticle = true loadWebView() From 4795efbed4ddc0281bf42f7d72e2af25034b282a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 09:30:45 -0700 Subject: [PATCH 5/6] Ignore late scroll position callbacks that arrive after the article has changed. --- iOS/Article/WebViewController.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 625d54b43..37d5ab1d5 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -533,8 +533,14 @@ extension WebViewController: UIScrollViewDelegate { } @objc func scrollPositionDidChange() { + let articleIDWhenAsked = article?.articleID webView?.evaluateJavaScript("window.scrollY") { (scrollY, error) in guard error == nil else { return } + // A late callback must not record the previous article’s offset. + // + guard articleIDWhenAsked == self.article?.articleID else { + return + } let javascriptScrollY = scrollY as? Int ?? 0 // I don't know why this value gets returned sometimes, but it is in error guard javascriptScrollY != 33554432 else { return } From d991b21d6265809396c2c2263cf7eaedd47d3132 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 3 Aug 2026 09:32:46 -0700 Subject: [PATCH 6/6] Open handoff and deep link articles at the top instead of reusing the persisted scroll position. Fixes #5243. --- iOS/SceneCoordinator.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 373ba0a0b..961194a45 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -2532,21 +2532,20 @@ private extension SceneCoordinator { return false } - // Read values from UserDefaults (migration happens in restoreWindowState) - let isShowingExtractedArticle = AppDefaults.shared.isShowingExtractedArticle - let articleWindowScrollY = AppDefaults.shared.articleWindowScrollY - + // A handoff or deep link opens the article at the top — the persisted scroll + // position belongs to launch state restoration, not to this article. + // switch sidebarItemID { case .smartFeed, .folder: - let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) + let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID) if found { treeControllerDelegate.addFilterException(sidebarItemID) } return found case .feed: - let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) + let found = selectSidebarItemAndArticle(sidebarItemID: sidebarItemID, articleID: articleID) if found { treeControllerDelegate.addFilterException(sidebarItemID) if let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let folder = sidebarItemNode.parent?.representedObject as? Folder, let folderSidebarItemID = folder.sidebarItemID { @@ -2584,13 +2583,13 @@ private extension SceneCoordinator { return nil } - func selectSidebarItemAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String, isShowingExtractedArticle: Bool, articleWindowScrollY: Int) -> Bool { + func selectSidebarItemAndArticle(sidebarItemID: SidebarItemIdentifier, articleID: String) -> Bool { guard let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let sidebarItemIndexPath = indexPathFor(sidebarItemNode) else { return false } selectSidebarItem(indexPath: sidebarItemIndexPath) { - self.selectArticleInCurrentFeed(articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) + self.selectArticleInCurrentFeed(articleID) } return true