Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<T> {
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<ViewHolderCollectionRef>;
/** 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<T>(props: RecyclerViewProps<T>) {
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<T> {
/** Map of indices to React keys for each rendered item */
renderStack: Map<string, { 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<ViewHolderCollectionRef>;
/** Map to store refs for each ViewHolder instance */
@@ -176,6 +176,13 @@ export function ViewHolderCollection<T>(props: ViewHolderCollectionProps<T>) {
{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<T>(props: ViewHolderCollectionProps<T>) {
item={item}
trailingItem={trailingItem}
layout={{
- ...getLayout(index),
+ ...layout,
}}
refHolder={refHolder}
onSizeChanged={onSizeChanged}
9 changes: 9 additions & 0 deletions patches/@shopify/flash-list/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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: 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
Loading