Fix crash when scrolling to oldest message on an empty table - #292
Merged
Merged
Conversation
performScrollTo's .oldestMessage branch clamps the section index with
max(numberOfSections - 1, 0), so an empty table still asks UIKit for
section 0:
Requested the number of rows for section (0) which is out of bounds.
The existing `guard lastRow >= 0` never fires, because max(_, 0) already
forced it non-negative, and it runs after the offending call anyway.
Guard on the section count first, then drop both clamps so the row guard
becomes meaningful for an empty section.
This is reachable in normal use: onStatusBarTap sets
pendingScrollTo = .oldestMessage, and the subscription is a global
NotificationCenter observer torn down in onDisappear, which does not fire
while a ChatView stays mounted off screen (a TabView tab, or lower in a
NavigationStack). A status bar tap from another screen then scrolls a chat
whose table is still empty, and the app crashes.
fayharinn
force-pushed
the
fix/scroll-to-oldest-on-empty-table
branch
from
August 14, 2026 07:39
3d1aeb5 to
f9ecf93
Compare
Collaborator
|
Hey @fayharinn, thank you so much for the fix, have a brilliant day! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #291.
performScrollTo's.oldestMessagebranch clamps the section index withmax(numberOfSections - 1, 0), so an empty table still asks UIKit for section 0:The existing
guard lastRow >= 0never fires, becausemax(_, 0)already forced the value non-negative, and it runs after the offending call anyway.This guards on the section count first, then drops both clamps so the row guard becomes meaningful for an empty section. No behaviour change on a populated table.
The path is reachable in normal use:
onStatusBarTaparmspendingScrollTo = .oldestMessage, and that subscription is a globalNotificationCenterobserver released inonDisappear, which does not fire while aChatViewstays mounted off screen (aTabViewtab, or lower in aNavigationStack). A status bar tap from another screen then scrolls a chat whose table is still empty. Issue #291 has the full trace and reproduction steps.Observed on iOS 27.0 with 3.1.7; the same code is on
mainand in 3.2.7.