From 4fd566cd450a4963ddd6ab88502194fa3b1c453f Mon Sep 17 00:00:00 2001 From: "Vinh Hoang (via MelvinBot)" Date: Fri, 7 Aug 2026 01:15:13 +0000 Subject: [PATCH 1/4] Add flash-list patch guarding ViewHolderCollection render against stale layout index Co-authored-by: Vinh Hoang --- ...gnore-stale-viewholder-render-layout.patch | 97 +++++++++++++++++++ patches/@shopify/flash-list/details.md | 9 ++ 2 files changed, 106 insertions(+) create mode 100644 patches/@shopify/flash-list/@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch diff --git a/patches/@shopify/flash-list/@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch b/patches/@shopify/flash-list/@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch new file mode 100644 index 000000000000..572d6b9790bf --- /dev/null +++ b/patches/@shopify/flash-list/@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch @@ -0,0 +1,97 @@ +diff --git a/node_modules/@shopify/flash-list/dist/recyclerview/RecyclerView.js b/node_modules/@shopify/flash-list/dist/recyclerview/RecyclerView.js +--- a/node_modules/@shopify/flash-list/dist/recyclerview/RecyclerView.js ++++ b/node_modules/@shopify/flash-list/dist/recyclerview/RecyclerView.js +@@ -467,7 +467,7 @@ function RecyclerView(props) { + isHorizontalRTL && viewToMeasureBoundedSize, + renderHeader, + !isHorizontalRTL && viewToMeasureBoundedSize, +- React.createElement(ViewHolderCollection, { viewHolderCollectionRef: viewHolderCollectionRef, data: data, horizontal: horizontal, renderStack: recyclerViewManager.getRenderStack(), getLayout: (index) => recyclerViewManager.getLayout(index), getAdjustmentMargin: () => { ++ React.createElement(ViewHolderCollection, { viewHolderCollectionRef: viewHolderCollectionRef, data: data, horizontal: horizontal, renderStack: recyclerViewManager.getRenderStack(), getLayout: (index) => recyclerViewManager.tryGetLayout(index), getAdjustmentMargin: () => { + if (!shouldRenderFromBottom || !recyclerViewManager.hasLayout()) { + return 0; + } +diff --git a/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.d.ts b/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.d.ts +--- a/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.d.ts ++++ b/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.d.ts +@@ -19,7 +19,7 @@ export interface ViewHolderCollectionProps { + index: number; + }>; + /** Function to get layout information for a specific index */ +- getLayout: (index: number) => RVLayout; ++ getLayout: (index: number) => RVLayout | undefined; + /** Ref to control layout updates from parent components */ + viewHolderCollectionRef: React.Ref; + /** Map to store refs for each ViewHolder instance */ +diff --git a/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.js b/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.js +--- a/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.js ++++ b/node_modules/@shopify/flash-list/dist/recyclerview/ViewHolderCollection.js +@@ -290,6 +290,13 @@ export function ViewHolderCollection(props) { + return (React.createElement(CompatView, { ref: containerRef, style: hasData && containerStyle }, containerLayout && + hasData && + renderEntriesRef.current.map(([reactKey, { index }]) => { ++ const layout = getLayout(index); ++ // The render stack can retain an entry whose index points past the ++ // end of the current layouts array when the data length shrinks ++ // mid-render. Skip it instead of throwing indexOutOfBounds. ++ if (layout === undefined) { ++ return null; ++ } + const item = data[index]; + // Suppress separators for items in the last row to prevent + // height mismatch. The last data item has no separator (no +@@ -298,7 +305,7 @@ export function ViewHolderCollection(props) { + ? data[index + 1] + : undefined; + return (React.createElement(ViewHolder, { key: reactKey, index: index, item: item, trailingItem: trailingItem, layout: { +- ...getLayout(index), ++ ...layout, + }, refHolder: refHolder, onSizeChanged: onSizeChanged, target: "Cell", renderItem: renderItem, extraData: extraData, CellRendererComponent: CellRendererComponent, ItemSeparatorComponent: ItemSeparatorComponent, horizontal: horizontal, hidden: hideStickyHeaderRelatedCell && currentStickyIndex === index, inverted: inverted })); + }))); + }; +diff --git a/node_modules/@shopify/flash-list/src/recyclerview/RecyclerView.tsx b/node_modules/@shopify/flash-list/src/recyclerview/RecyclerView.tsx +--- a/node_modules/@shopify/flash-list/src/recyclerview/RecyclerView.tsx ++++ b/node_modules/@shopify/flash-list/src/recyclerview/RecyclerView.tsx +@@ -705,7 +705,7 @@ function RecyclerView(props: RecyclerViewProps) { + data={data} + horizontal={horizontal} + renderStack={recyclerViewManager.getRenderStack()} +- getLayout={(index) => recyclerViewManager.getLayout(index)} ++ getLayout={(index) => recyclerViewManager.tryGetLayout(index)} + getAdjustmentMargin={() => { + if (!shouldRenderFromBottom || !recyclerViewManager.hasLayout()) { + return 0; +diff --git a/node_modules/@shopify/flash-list/src/recyclerview/ViewHolderCollection.tsx b/node_modules/@shopify/flash-list/src/recyclerview/ViewHolderCollection.tsx +--- a/node_modules/@shopify/flash-list/src/recyclerview/ViewHolderCollection.tsx ++++ b/node_modules/@shopify/flash-list/src/recyclerview/ViewHolderCollection.tsx +@@ -23,7 +23,7 @@ export interface ViewHolderCollectionProps { + /** Map of indices to React keys for each rendered item */ + renderStack: Map; + /** Function to get layout information for a specific index */ +- getLayout: (index: number) => RVLayout; ++ getLayout: (index: number) => RVLayout | undefined; + /** Ref to control layout updates from parent components */ + viewHolderCollectionRef: React.Ref; + /** Map to store refs for each ViewHolder instance */ +@@ -176,6 +176,13 @@ export function ViewHolderCollection(props: ViewHolderCollectionProps) { + {containerLayout && + hasData && + Array.from(renderStack.entries(), ([reactKey, { index }]) => { ++ const layout = getLayout(index); ++ // The render stack can retain an entry whose index points past the ++ // end of the current layouts array when the data length shrinks ++ // mid-render. Skip it instead of throwing indexOutOfBounds. ++ if (layout === undefined) { ++ return null; ++ } + const item = data[index]; + // Suppress separators for items in the last row to prevent + // height mismatch. The last data item has no separator (no +@@ -192,7 +199,7 @@ export function ViewHolderCollection(props: ViewHolderCollectionProps) { + item={item} + trailingItem={trailingItem} + layout={{ +- ...getLayout(index), ++ ...layout, + }} + refHolder={refHolder} + onSizeChanged={onSizeChanged} diff --git a/patches/@shopify/flash-list/details.md b/patches/@shopify/flash-list/details.md index 741df7a67733..a35aeb79553e 100644 --- a/patches/@shopify/flash-list/details.md +++ b/patches/@shopify/flash-list/details.md @@ -192,3 +192,12 @@ - Upstream PR/issue: TBD - E/App issue: https://github.com/Expensify/App/issues/91425 - PR introducing patch: https://github.com/Expensify/App/pull/91422 + +### [@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch](@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch) + +- Reason: Prevents a web-only `index out of bounds, not enough layouts` crash thrown while `ViewHolderCollection` renders. This is the render-path sibling of patch `009`, which only guarded the `validateItemSize` measurement callback. On web, `ViewHolderCollection` incrementally reconciles `renderEntriesRef` and can retain a render entry whose stored `index` points past the end of the current `layouts` array after the list `data` shrinks between renders (e.g. deleting a report action, IOU actions being filtered once transactions load, or a Concierge draft being removed). The retained entry then calls the unguarded `getLayout(index)` wired at `RecyclerView` → `LayoutManager.getLayout`, which throws. The patch wires `ViewHolderCollection`'s `getLayout` prop to the bounds-safe `recyclerViewManager.tryGetLayout(index)` and skips (returns `null` for) any render entry whose layout is `undefined`, so a stale index is dropped for that render instead of crashing. Native rebuilds render entries from scratch each render and never hits this, matching the web-only Sentry reports. +- Files changed: `src/recyclerview/RecyclerView.tsx`, `src/recyclerview/ViewHolderCollection.tsx`, and their `dist` counterparts (`dist/recyclerview/RecyclerView.js`, `dist/recyclerview/ViewHolderCollection.js`, `dist/recyclerview/ViewHolderCollection.d.ts`). +- Upstream PR/issue: TBD +- E/App issue: https://github.com/Expensify/App/issues/97472 +- Sentry: https://expensify.sentry.io/issues/APP-EEE +- PR introducing patch: TBD (this PR) From 2cdab627f0c1b32005f613034ac45b7b5bea7e13 Mon Sep 17 00:00:00 2001 From: "Vinh Hoang (via MelvinBot)" Date: Fri, 7 Aug 2026 01:18:20 +0000 Subject: [PATCH 2/4] Link PR in flash-list patch 016 details Co-authored-by: Vinh Hoang --- patches/@shopify/flash-list/details.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/@shopify/flash-list/details.md b/patches/@shopify/flash-list/details.md index a35aeb79553e..be55828a6a99 100644 --- a/patches/@shopify/flash-list/details.md +++ b/patches/@shopify/flash-list/details.md @@ -200,4 +200,4 @@ - Upstream PR/issue: TBD - E/App issue: https://github.com/Expensify/App/issues/97472 - Sentry: https://expensify.sentry.io/issues/APP-EEE -- PR introducing patch: TBD (this PR) +- PR introducing patch: https://github.com/Expensify/App/pull/98015 From 886f50bf8009a13ef1c4511c356c4c2ecffd7e1b Mon Sep 17 00:00:00 2001 From: "Vinh Hoang (via MelvinBot)" Date: Thu, 13 Aug 2026 09:13:49 +0000 Subject: [PATCH 3/4] Correct patch 016 root cause in details.md (upstream, all-platform) Co-authored-by: Vinh Hoang --- patches/@shopify/flash-list/details.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/@shopify/flash-list/details.md b/patches/@shopify/flash-list/details.md index be55828a6a99..1af8a6823ba8 100644 --- a/patches/@shopify/flash-list/details.md +++ b/patches/@shopify/flash-list/details.md @@ -195,9 +195,9 @@ ### [@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch](@shopify+flash-list+2.3.0+016+ignore-stale-viewholder-render-layout.patch) -- Reason: Prevents a web-only `index out of bounds, not enough layouts` crash thrown while `ViewHolderCollection` renders. This is the render-path sibling of patch `009`, which only guarded the `validateItemSize` measurement callback. On web, `ViewHolderCollection` incrementally reconciles `renderEntriesRef` and can retain a render entry whose stored `index` points past the end of the current `layouts` array after the list `data` shrinks between renders (e.g. deleting a report action, IOU actions being filtered once transactions load, or a Concierge draft being removed). The retained entry then calls the unguarded `getLayout(index)` wired at `RecyclerView` → `LayoutManager.getLayout`, which throws. The patch wires `ViewHolderCollection`'s `getLayout` prop to the bounds-safe `recyclerViewManager.tryGetLayout(index)` and skips (returns `null` for) any render entry whose layout is `undefined`, so a stale index is dropped for that render instead of crashing. Native rebuilds render entries from scratch each render and never hits this, matching the web-only Sentry reports. +- Reason: Prevents an `index out of bounds, not enough layouts` crash thrown while `ViewHolderCollection` renders. This is the render-path sibling of patch `009`, which only guarded the `validateItemSize` measurement callback. The crash originates in upstream flash-list and reproduces on **every platform** (native crash: `APP-8PG`), not just web. The render stack (`RenderStackManager.keyMap`, returned by `RecyclerViewManager.getRenderStack()`) can hold an entry whose stored `index` exceeds the current `layouts` length when the list `data` shrinks between renders (e.g. deleting a report action, IOU actions being filtered once transactions load, or a Concierge draft being removed). This is a timing gap inside flash-list's own update pipeline: on a data shrink `LayoutManager.modifyLayout` truncates `this.layouts` synchronously (`getLayoutCount()` drops immediately), but the render stack is pruned of the now-out-of-bounds keys only later, when `RenderStackManager.sync()` runs. Any render committed in that gap iterates a `keyMap` still carrying a pre-shrink `index` against the already-shortened `layouts`, so the unguarded `getLayout(index)` wired at `RecyclerView` → `LayoutManager.getLayout` throws. Upstream already guards this same staleness on the measurement path — `modifyLayout` filters stale `layoutInfo` with the comment _"layoutInfo may contain stale indices from ViewHolders that were rendered before the data shrunk"_ — but left the render path unguarded. The patch wires `ViewHolderCollection`'s `getLayout` prop to the bounds-safe `recyclerViewManager.tryGetLayout(index)` and skips (returns `null` for) any render entry whose layout is `undefined`, so a stale index is dropped for that render instead of crashing. Because `keyMap`/`LayoutManager` are shared, platform-agnostic state, the guard applies on both render branches — web's `renderEntriesRef.current.map` and native's `Array.from(renderStack.entries())`. Patch `011` (which introduces web's `renderEntriesRef` copy) only carries the index forward; it is not the source of the stale index. - Files changed: `src/recyclerview/RecyclerView.tsx`, `src/recyclerview/ViewHolderCollection.tsx`, and their `dist` counterparts (`dist/recyclerview/RecyclerView.js`, `dist/recyclerview/ViewHolderCollection.js`, `dist/recyclerview/ViewHolderCollection.d.ts`). - Upstream PR/issue: TBD - E/App issue: https://github.com/Expensify/App/issues/97472 -- Sentry: https://expensify.sentry.io/issues/APP-EEE +- Sentry: https://expensify.sentry.io/issues/APP-8PG - PR introducing patch: https://github.com/Expensify/App/pull/98015 From 3226d420374fd76f5b62773ce5d748837a813328 Mon Sep 17 00:00:00 2001 From: "Vinh Hoang (via MelvinBot)" Date: Thu, 13 Aug 2026 17:51:30 +0000 Subject: [PATCH 4/4] Add upstream flash-list issue link to patch 016 details Co-authored-by: Vinh Hoang --- patches/@shopify/flash-list/details.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/@shopify/flash-list/details.md b/patches/@shopify/flash-list/details.md index 1af8a6823ba8..c2a5178df699 100644 --- a/patches/@shopify/flash-list/details.md +++ b/patches/@shopify/flash-list/details.md @@ -197,7 +197,7 @@ - Reason: Prevents an `index out of bounds, not enough layouts` crash thrown while `ViewHolderCollection` renders. This is the render-path sibling of patch `009`, which only guarded the `validateItemSize` measurement callback. The crash originates in upstream flash-list and reproduces on **every platform** (native crash: `APP-8PG`), not just web. The render stack (`RenderStackManager.keyMap`, returned by `RecyclerViewManager.getRenderStack()`) can hold an entry whose stored `index` exceeds the current `layouts` length when the list `data` shrinks between renders (e.g. deleting a report action, IOU actions being filtered once transactions load, or a Concierge draft being removed). This is a timing gap inside flash-list's own update pipeline: on a data shrink `LayoutManager.modifyLayout` truncates `this.layouts` synchronously (`getLayoutCount()` drops immediately), but the render stack is pruned of the now-out-of-bounds keys only later, when `RenderStackManager.sync()` runs. Any render committed in that gap iterates a `keyMap` still carrying a pre-shrink `index` against the already-shortened `layouts`, so the unguarded `getLayout(index)` wired at `RecyclerView` → `LayoutManager.getLayout` throws. Upstream already guards this same staleness on the measurement path — `modifyLayout` filters stale `layoutInfo` with the comment _"layoutInfo may contain stale indices from ViewHolders that were rendered before the data shrunk"_ — but left the render path unguarded. The patch wires `ViewHolderCollection`'s `getLayout` prop to the bounds-safe `recyclerViewManager.tryGetLayout(index)` and skips (returns `null` for) any render entry whose layout is `undefined`, so a stale index is dropped for that render instead of crashing. Because `keyMap`/`LayoutManager` are shared, platform-agnostic state, the guard applies on both render branches — web's `renderEntriesRef.current.map` and native's `Array.from(renderStack.entries())`. Patch `011` (which introduces web's `renderEntriesRef` copy) only carries the index forward; it is not the source of the stale index. - Files changed: `src/recyclerview/RecyclerView.tsx`, `src/recyclerview/ViewHolderCollection.tsx`, and their `dist` counterparts (`dist/recyclerview/RecyclerView.js`, `dist/recyclerview/ViewHolderCollection.js`, `dist/recyclerview/ViewHolderCollection.d.ts`). -- Upstream PR/issue: TBD +- Upstream PR/issue: https://github.com/Shopify/flash-list/issues/2440 - E/App issue: https://github.com/Expensify/App/issues/97472 - Sentry: https://expensify.sentry.io/issues/APP-8PG - PR introducing patch: https://github.com/Expensify/App/pull/98015