From 6a5753fac8bfd6a60dd3e5fa0b44815df3e2bcdb Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 31 Oct 2022 17:45:36 -0400 Subject: [PATCH] Fix crash when tapping Load More button with Disable Infinite Scrolling --- Tusker/TimelineLikeController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tusker/TimelineLikeController.swift b/Tusker/TimelineLikeController.swift index 523bc58d..3e41bdb7 100644 --- a/Tusker/TimelineLikeController.swift +++ b/Tusker/TimelineLikeController.swift @@ -96,7 +96,11 @@ actor TimelineLikeController { return } let token = LoadAttemptToken() - guard await delegate.canLoadOlder() else { + guard await delegate.canLoadOlder(), + // Make sure we're still in the idle state before continuing on, since that may have chnaged while waiting for user input. + // If the load more cell appears, then the users scrolls up and back down, the VC may kick off a second loadOlder task + // but we only want one to proceed. The actor prevents a data race, and this prevents multiple simultaneousl loadOlder tasks from running. + state == .idle else { return } state = .loadingOlder(token, hasAddedLoadingIndicator: false)