Skip to content

fix: land initial-mount scroll adjustments once before revealing the list - #600

Open
chrispader wants to merge 1 commit into
LegendApp:mainfrom
chrispader:fix/ready-after-initial-adjustments
Open

chrispader wants to merge 1 commit into
LegendApp:mainfrom
chrispader:fix/ready-after-initial-adjustments

Conversation

@chrispader

@chrispader chrispader commented Nov 5, 2026 •

Copy link
Copy Markdown

Before a list is ready, requestAdjust moves state.scroll and the item positions right away but applies the native scroll adjustment on the next frame. setInitialRenderState could mark the list ready before that frame ran, so the items appeared at the unadjusted offset and jumped once the adjustment landed. A native initial scroll dispatched in between also already targets the adjusted offset, so the late anchor move shifted the list a second time, and completion retries reissued the offset recorded at dispatch.

With this change, the list becomes ready only after every adjustment queued before that point has run. A deferred adjustment is skipped when an absolute native scroll was issued after it was requested, and the target of an in-flight native initial scroll moves with each adjustment. Web retargets from the index and is unchanged.

// initialScrollIndex: { index: 37, viewOffset: 40 }; item 37 is at 1618 after the first measurements.
// The initial scroll targets 1578. Then the deferred adjustments for those measurements land: -172.
// Before: native ends at 1406, the fallback reissues 1578, and later rows (-36) leave item 37 at 4 instead of 40.
// After: native stays at 1578, the target follows to 1542, and the list appears with item 37 40 points below the top.

The queued callback now also owns the adjustingFromInitialMount counter. Before, only the regular path decremented it, so the Android old-architecture workaround would have kept the list hidden.

This PR now also contains the deferred-adjustment fix from #604, because both change the same callback. #604 keeps only the silent-retry fix and builds on this PR.

We hit this in Expensify/App#100733, which moves the chat message list to LegendList. On iOS and Android, a chat that opens at a linked message showed the message at the top of the list and then moved it down to its offset. Expensify currently carries this fix as a patch.

Reproduction

  1. On iOS or Android, render a list with initialScrollIndex: { index: 37, viewOffset: 40 } whose items above index 37 render smaller than estimatedItemSize.
  2. Open the screen with the list.
  3. Verify the item at index 37 first appears 40 points below the top and doesn't move afterward.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-05T11:34:19.443832Z
We couldn’t complete this review. Comment @codex review to try again.
062938a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

chrispader added a commit to margelo/Expensify that referenced this pull request Nov 5, 2026
…ents

LegendList could mark a list ready and show it one frame before the native scroll adjustment for items measured during its initial layout ran. On iOS, a chat that opens at a linked message showed the message at the top and then moved it down by about 45 points. The patch carries LegendApp/legend-list#600 until it is released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chrispader
chrispader force-pushed the fix/ready-after-initial-adjustments branch from 062938a to 240eed4 Compare November 9, 2026 10:53
…list

Before the list is ready, requestAdjust moves state.scroll and the item
positions right away but applies the native scroll adjustment on the next
frame. Two things went wrong in between.

setInitialRenderState could mark the list ready before that frame ran, so the
containers became visible with items at the unadjusted offset and jumped once
the adjustment landed. Readiness now waits until every adjustment queued
before the list was ready has run, and the last one re-checks readiness. The
queued callback owns the adjustingFromInitialMount counter, so the Android
old-architecture workaround path releases it too.

A native initial scroll dispatched in that frame already targets the adjusted
offset, so moving the anchor afterwards shifted the list a second time. A
deferred adjustment is now skipped when an absolute native scroll was issued
after it was requested. The in-flight native initial scroll target also moves
with each adjustment, so completion retries reissue the current offset
instead of the one recorded at dispatch. Web retargets from the index and is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chrispader
chrispader force-pushed the fix/ready-after-initial-adjustments branch from 240eed4 to 0e6e62b Compare November 11, 2026 12:15
chrispader added a commit to chrispader/legend-list that referenced this pull request Nov 11, 2026
When an Android initial scroll dispatches without a native scroll event, the
completion fallback retries it by nudging the offset one point away and
returning to the target on the next frame. Two things could leave the list
off its target.

Another completion check could finish the scroll before the return frame ran.
Finishing cancelled the frame, so the list stayed one point away from its
target. Finishing now runs a pending return first.

The return also reissued the offset recorded before the nudge. Adjustments
that land in between move the target (LegendApp#600), so the return now reads the
watchdog's current target offset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chrispader chrispader changed the title fix: reveal the list only after initial-mount scroll adjustments land fix: land initial-mount scroll adjustments once before revealing the list Nov 11, 2026
chrispader added a commit to margelo/Expensify that referenced this pull request Nov 12, 2026
Each LegendList patch is now the build output of its upstream PR, so the
patches change exactly what the PRs change, in every bundle the PRs touch.

- 001 and 003 now also patch the native bundles, as their PRs change shared
  code.
- 002 adds the explicit maintainVisibleContentPosition anchor option that
  LegendApp/legend-list#597 now proposes, instead of anchoring the last
  visible item in every list with alignItemsAtEnd.
- 004 contains LegendApp/legend-list#600, which now also skips deferred
  adjustments that a later native scroll already includes and moves the
  initial scroll target with each adjustment.
- 006 keeps only the silent-retry fix from LegendApp/legend-list#604.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant