Skip to content

fix: ignore viewability updates before the first layout - #2556

Open
zacyungblut wants to merge 2 commits into
Shopify:mainfrom
zacyungblut:fix/pre-layout-viewability-guard
Open

zacyungblut wants to merge 2 commits into
Shopify:mainfrom
zacyungblut:fix/pre-layout-viewability-guard

Conversation

@zacyungblut

Copy link
Copy Markdown

Summary

Fixes #2551.

A scroll event that arrives before the list's first layout crashes the app with LayoutManager is not initialized, window size is unavailable. RecyclerViewManager.getWindowSize() (and computeVisibleIndices()) throw while layoutManager is still undefined, so the undefined guard in ViewabilityManager.updateViewableItems never gets a chance to run. The event can come from a user gesture or momentum scroll while the list is mounting or remounting.

Changes

  • RecyclerViewManager.recordInteraction() and computeItemViewability() now return early when hasLayout() is false. The first layout already triggers a viewability update, so pre-layout scroll events are safe to ignore, matching the issue's expected behavior.
  • Added a regression test covering both calls on a manager with no layout yet.

Test plan

  • Added src/__tests__/RecyclerViewManager.test.ts case: constructing a manager with onViewableItemsChanged set, then calling recordInteraction() and computeItemViewability() before layout, no longer throws.

Add checks for layout before processing viewability and interactions.
Add test for viewability updates before the first layout in RecyclerViewManager.

This branch has not been deployed

No deployments
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.

LayoutManager is not initialized, window size is unavailable when a scroll event arrives before the first layout

1 participant