Skip to content

Fix index out of bounds in viewability computation#2087

Merged
naqvitalha merged 1 commit intomainfrom
fix-index-out-of-bounds
Feb 3, 2026
Merged

Fix index out of bounds in viewability computation#2087
naqvitalha merged 1 commit intomainfrom
fix-index-out-of-bounds

Conversation

@naqvitalha
Copy link
Collaborator

Summary

Fixes an index out of bounds error in viewability computation.

Problem

The previous implementation of recomputeViewableItems() would:

  1. Clear the last reported viewable indices
  2. Immediately call updateViewableItems()

This could use stale or invalid indices leading to index out of bounds errors when the data has changed.

Solution

This fix separates the operations in RecyclerViewManager.recomputeViewableItems():

  1. Clear the last reported viewable indices via clearLastReportedViewableIndices()
  2. Call computeItemViewability() which properly computes fresh visible indices before updating viewable items

This ensures the indices are always freshly computed from the current state before being used, preventing index out of bounds errors.

Changes

  • ViewabilityManager.recomputeViewableItems() renamed to clearLastReportedViewableIndices() and simplified to only clear indices
  • RecyclerViewManager.recomputeViewableItems() now calls clearLastReportedViewableIndices() followed by computeItemViewability()

The previous implementation of recomputeViewableItems() would clear the
last reported viewable indices and then immediately call updateViewableItems(),
which could use stale or invalid indices leading to index out of bounds errors.

This fix separates the operations:
1. Clear the last reported viewable indices
2. Call computeItemViewability() which properly computes fresh visible indices
   before updating viewable items

This ensures the indices are always freshly computed from the current state
before being used, preventing index out of bounds errors.
@naqvitalha naqvitalha enabled auto-merge (squash) February 3, 2026 20:28
@naqvitalha naqvitalha merged commit 4c000e0 into main Feb 3, 2026
11 checks passed
@naqvitalha naqvitalha deleted the fix-index-out-of-bounds branch February 3, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants