Skip to content

Commit b9eb516

Browse files
committed
Reduce number of setState calls when lists are nested
1 parent e44dbc4 commit b9eb516

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/recyclerview/RecyclerView.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ const RecyclerViewComponent = <T,>(
227227
viewHolderCollectionRef.current?.commitLayout();
228228
applyOffsetCorrection();
229229
}
230+
231+
if (
232+
horizontal &&
233+
recyclerViewManager.hasLayout() &&
234+
recyclerViewManager.getWindowSize().height > 0
235+
) {
236+
// We want the parent FlashList to continue rendering the next batch of items as soon as height is available.
237+
// Waiting for each horizontal list to finish might cause too many setState calls.
238+
// This will help avoid "Maximum update depth exceeded" error.
239+
parentRecyclerViewContext?.unmarkChildLayoutAsPending(recyclerViewId);
240+
}
230241
});
231242

232243
/**

src/recyclerview/RecyclerViewManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class RecyclerViewManager<T> {
3838

3939
public firstItemOffset = 0;
4040
public ignoreScrollEvents = false;
41+
public isFirstPaintOnUiComplete = false;
4142

4243
public get animationOptimizationsEnabled() {
4344
return this._animationOptimizationsEnabled;
@@ -263,6 +264,9 @@ export class RecyclerViewManager<T> {
263264
return true;
264265
}
265266
if (this.hasRenderedProgressively) {
267+
if (!this.isFirstPaintOnUiComplete) {
268+
return false;
269+
}
266270
return this.recomputeEngagedIndices() !== undefined;
267271
} else {
268272
this.renderProgressively();

src/recyclerview/hooks/useOnLoad.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const useOnListLoad = <T>(
4848
// console.log("----------> dataCollector", dataCollectorString);
4949
// console.log("----------> FlashList v2 load in", `${elapsedTimeInMs} ms`);
5050
requestAnimationFrame(() => {
51+
recyclerViewManager.isFirstPaintOnUiComplete = true;
5152
onLoad?.({ elapsedTimeInMs });
5253
setIsLoaded(true);
5354
});

0 commit comments

Comments
 (0)