Skip to content

Commit fbf817b

Browse files
authored
Fix crash when pushing the same VC twice in Reader (#23907)
2 parents 046a6c6 + b00da1e commit fbf817b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [*] Fix minor appearance issues in the Blaze campaign list [#23891]
1616
* [*] Improve the sidebar animations and layout on some iPad models [#23886]
1717
* [*] Fix an issue with posts shown embedded in the notifications popover on iPad [#23889]
18+
* [*] Fix a couple of rare crashes in Reader [#23907]
1819
* [*] The post cover now uses the standard aspect ratio for covers, so there is no jumping. There are also a few minor improvements to the layout and animations of the cover [#23897]
1920
* [*] Move the "Reading Preferences" button to the "More" menu [#23897]
2021

WordPress/Classes/System/Root View/ReaderPresenter.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
9292
} else {
9393
if let latestContentVC {
9494
// Return to the previous view controller preserving its state
95-
mainNavigationController.pushViewController(latestContentVC, animated: true)
95+
mainNavigationController.safePushViewController(latestContentVC, animated: true)
9696
}
9797
}
9898
}
@@ -191,7 +191,7 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
191191
splitViewController.setViewController(navigationVC, for: .secondary)
192192
} else {
193193
latestContentVC = viewController
194-
mainNavigationController.pushViewController(viewController, animated: true)
194+
mainNavigationController.safePushViewController(viewController, animated: true)
195195
}
196196
}
197197

@@ -201,9 +201,9 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
201201
if let splitViewController {
202202
let navigationVC = splitViewController.viewController(for: .secondary) as? UINavigationController
203203
wpAssert(navigationVC != nil)
204-
navigationVC?.pushViewController(viewController, animated: true)
204+
navigationVC?.safePushViewController(viewController, animated: true)
205205
} else {
206-
mainNavigationController.pushViewController(viewController, animated: true)
206+
mainNavigationController.safePushViewController(viewController, animated: true)
207207
}
208208
}
209209

@@ -248,3 +248,14 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
248248
}
249249
}
250250
}
251+
252+
private extension UINavigationController {
253+
// TODO: fix when stack trace becomes available
254+
// A workaround for https://a8c.sentry.io/issues/3140539221.
255+
func safePushViewController(_ viewController: UIViewController, animated: Bool) {
256+
guard !children.contains(viewController) else {
257+
return wpAssertionFailure("pushing the same view controller more than once", userInfo: ["viewController": "\(viewController)"])
258+
}
259+
pushViewController(viewController, animated: animated)
260+
}
261+
}

0 commit comments

Comments
 (0)