Skip to content

fix: crash in topIndexPath - WPB-23912#4409

Draft
netbe wants to merge 1 commit intodevelopfrom
fix/crash-conversation-WPB-23912
Draft

fix: crash in topIndexPath - WPB-23912#4409
netbe wants to merge 1 commit intodevelopfrom
fix/crash-conversation-WPB-23912

Conversation

@netbe
Copy link
Copy Markdown
Collaborator

@netbe netbe commented Mar 9, 2026

BugWPB-23912 [iOS] crash on topIndexPath(for:) ConversationTableViewDataSource.swift:571

Issue

The app crashed when scrolling to a specific message (e.g. via push notification or search result) in a long conversation while background sync was active.

topIndexPath(for:) called tableView.numberOfRows(inSection:) with a section index derived from the fetch controller. Because calculateSections snapshots allMessages before dispatching to a background thread, the
fetch controller can gain new objects (via NSFetchedResultsControllerDelegate) by the time the result is applied and reloadData() is called. This made the fetch controller index exceed the number of sections the
table view knew about, triggering UIKit's internal assertion.

The fix changes index(of:) to look up the message by nonce in currentSections instead of the fetch controller. Since currentSections is always the exact snapshot the table view was last reloaded with, the
returned index is guaranteed to be in bounds.

Testing

  1. Open a conversation with significantly more than 30 messages.
  2. While the conversation is open and receiving new messages, trigger a scroll to an old message — either by tapping a push notification or using message search and jumping to a result.
  3. Verify the app does not crash and scrolls to the correct message.

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

…on mismatch - WPB-23912

Use currentSections to resolve a message's section index instead of the
fetch controller, ensuring the index is always consistent with what the
table view displays and eliminating the race condition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 9, 2026

@netbe netbe added the WIP label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants