Skip to content

fix(layout): guard validateItemSize against stale onLayout indices#2293

Open
narumichi0710 wants to merge 1 commit into
Shopify:mainfrom
narumichi0710:fix/2291-stale-viewholder-onlayout-guard
Open

fix(layout): guard validateItemSize against stale onLayout indices#2293
narumichi0710 wants to merge 1 commit into
Shopify:mainfrom
narumichi0710:fix/2291-stale-viewholder-onlayout-guard

Conversation

@narumichi0710
Copy link
Copy Markdown

@narumichi0710 narumichi0710 commented May 24, 2026

Description

Fixes #2291

ViewHolder.onLayout can fire after the list's layout table has changed during fast data updates or navigation. validateItemSize was calling getLayout(index), which throws when the render-time index is no longer valid in the layout manager.

Switch to tryGetLayout(index) and return early when it is undefined. Same pattern as StickyHeaders and useRecyclerViewController.

The same fix is running in production via Expensify's local patch (Expensify/App#91248).

Reviewers' hat-rack 🎩

  • RecyclerView.tsx: 1-line change, swap to tryGetLayout + early return
  • RecyclerViewManager.test.ts: helpers lifted to parent describe, two boundary tests added

Test plan

  • yarn test --forceExit — 187 tests pass, including 2 new boundary tests for tryGetLayout
  • yarn type-check passes
  • yarn lint passes
  • yarn build passes

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.

Stale ViewHolder onLayout can throw when its layout index no longer exists

1 participant