With TalkBack running, the app crashes when messages load into a chat while the screen reader is reading it. The most reliable way to hit it is opening a chat from search, so the chat opens empty and then fills in. It also happens when scrolling to the end of a comment thread loads more comments.
Steps to reproduce
Turn TalkBack on.
Search for a message, using the search inside a chat or the global search on the chat list.
Open the search result. The chat opens empty and then the messages load in.
Let TalkBack keep accessibility focus on a message while the rest load in.
Repeat a few times, or open a channel post's comments and scroll to the end so more comments load.
Expected: the chat loads and TalkBack keeps reading.
Actual: the app crashes.
java.lang.IndexOutOfBoundsException: invalid position 61. State item count is 24
at RecyclerView$Recycler.convertPreLayoutPositionToPostLayout
at GridLayoutManager.getSpanGroupIndex
at GridLayoutManager.onInitializeAccessibilityNodeInfoForItem
at RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo
at ChatMessageCell.onInitializeAccessibilityNodeInfo
at ViewRootImpl.handleWindowContentChangedEvent
at RecyclerView.dispatchContentChangedIfNecessary
at RecyclerView.onExitLayoutOrScroll
at RecyclerView.dispatchLayoutStep1
The list sends a content-changed event from inside its own layout pass. Because a screen reader is holding accessibility focus on an item, the framework builds that item's node right away, which asks the layout manager for the item position while the ongoing layout has not settled positions yet, and that stale position is out of range for the new state.
Without a screen reader the node is never built, which is why this only happens with one running.
This only affects screen reader users, and it makes opening a chat from search unreliable.
I have a fix for this open as a pull request, if it is useful: https://github.com/DrKLO/Telegram/pull/1995