#2307·flash-list

在项大小超过 200 时,Flashlist v2 initialScrollIndex 会渲染错误的项

作者: VladimirAtGlossgenius创建于 2026年6月4日更新于 2026年9月8日
标签bugP1agent-triage

Description FlashList v2 displays wrong items when initialScrollIndex is set and the actual item size exceeds 200px (FlashList's internal averageWindow default). The list opens showing items roughly 83 indices past the requested index. ## Current behavior With initialScrollIndex={250} and items 300px tall, the list opens showing Item 333 instead of Item 250. The root cause is a race condition in FlashList's layout table construction: 1. applyInitialScrollAdjustment runs before any items are measured, building item positions using the default averageWindow of 200px. Item 250 is placed at 250 × 200 = 50,000px (should be 250 × 300 = 75,000px). 2. Item 250 renders at the wrong position, measures at 300px, and modifyLayout runs recomputeLayouts(250→500) — but this anchors items 251+ to item 249's stale 200px-based position (249 × 200 = 49,800px). Items 251+ are now at ~50,400px+. 3. applyInitialScrollAdjustment fires again with the updated averageWindow=300 and correctly places items 0–250 at i × 300px. Item 250 moves to 75,000px. However, items 251+ are not touched — they retain their wrong positions from step 2. 4. The layout table now has a backward jump at the 250→251 boundary (75,000 → 50,400), making it non-monotonic. 5. FlashList binary-searches the broken table to find which items to render at scroll position 75,000px. The search starts at mid=249, sees 74,700 < 75,000, goes right — and never checks item 250 (which is to the left). It finds item 333 (at position ~75,000 in the broken layout) and renders that instead. The bug only manifests when actual item size exceeds 200px. With smaller items (< 200px), the corrective pass moves items to a lower pixel position than what modifyLayout set, creating a forward gap that keeps the table monotonically sorted. ## Expected behavior The list should open with Item 250 visible at the top. ## Reproduction Expo Snack: https://snack.expo.dev/TgCTAo_9hg8zsXmGYrlya

内容来源: Shopify/flash-list