fix: complete non-zero initialScrollIndex on iOS without waiting for native scroll events - #500
Open
erank-pixel wants to merge 2 commits into
Open
Conversation
…native scroll events
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08c84df915
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On iOS, a list mounted with a non-zero
initialScrollIndexstays invisible (thereadyToRenderopacity gate) for seconds — in our production app we consistently measured 2.8–3.8s before the list appeared, while its content was mounted, laid out, and (in our case) already playing video/audio underneath.Root cause
The initial-scroll completion logic deadlocks on iOS:
scrollTo/contentOffset. iOS does not emit a scroll event for unanimated offset changes, sostate.hasScrollednever becomes true anddidDispatchNativeScrollkeeps gating.shouldFinishInitialScrollWithoutNativeProgressrefuses to finish whiledidDispatchNativeScroll(state) && !state.hasScrolled(and unconditionally forbootstrapsessions) — even whenstate.scrollandstate.scrollPendingalready match the target exactly.checkFinishedScrollthen re-issuesscrollToFallbackOffsetto the same offset — which again emits no event, because the offset doesn't change.readyToRenderflip and the list appear.Which of the two refusals bites depends on mount timing (session kind ends up
bootstrapon some mounts andoffseton others), which makes the stall look intermittent — that's what made it painful to track down.Fix
On iOS only, allow
shouldFinishInitialScrollWithoutNativeProgressto finish without observed native progress — the existing offset checks right below (state.scrollandstate.scrollPendingwithin 1px of the target) remain the real gate, and they're reliable there because unanimatedscrollToapplies synchronously. Android/web still emit the events and keep the stricter path, so their behavior is unchanged.After the fix our reveal times went from 2.8–3.8s to a consistent 120–370ms across dozens of cold mounts (production app, iPhone 13 / iOS 26, ~60-item list with fixed item heights,
initialScrollIndextypically 1–10).Repro
<LegendList data={items} initialScrollIndex={8} estimatedItemSize={FIXED} …/>where the list mounts with data already presentonLoadtiming / the list staying blank for seconds before appearing (worse on slower devices; timing-dependent, so try several mounts)Notes
Platform.OS === "ios"to keep the blast radius minimal, but if you'd prefer the offset-match check to be authoritative on all platforms (or a different structure entirely), happy to rework.bun testin this environment; the change has been running in a production app for a full day of heavy manual testing (cold mounts, remounts, in-place data swaps viadataKey, user scrolls immediately after mount) with no regressions observed.