Skip to content

PoC: Migrate to LegendList - #98270

Draft
chrispader wants to merge 45 commits into
Expensify:mainfrom
margelo:@chrispader/feat/legend-list
Draft

PoC: Migrate to LegendList#98270
chrispader wants to merge 45 commits into
Expensify:mainfrom
margelo:@chrispader/feat/legend-list

Conversation

@chrispader

@chrispader chrispader commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@roryabraham

Explanation of Change

The main chat history still uses FlashList's inverted-list behavior, which makes pagination, index calculations, and imperative scrolling depend on reversed coordinates. This PR migrates ReportActionsList to LegendList with chronological data and normal start/end semantics while preserving the existing chat behavior.

  • Reverses the derived report-action array without mutating the Onyx data and renders it directly with LegendList, without an inverted-list adapter.
  • Preserves initial positioning for the latest message, linked messages, unread markers, money requests, and transaction threads. A fresh list instance replaces the small cached page after the initial report data finishes loading.
  • Keeps older-action pagination at the visual start and newer-action pagination at the visual end while retaining the visible scroll position.
  • Enables item recycling, narrows item types by action and content size, and resets item-local state when a recycled cell receives another report action.
  • Updates scroll offsets, action indexes, viewability tracking, composer scroll events, action badges, message editing, and receipt previews to use chronological indexes.
  • Patches FullStory's static ref wrapper so recycled items do not receive a new ref callback on every render and enter a ref-driven update loop.
  • Removes the unused InvertedFlashList implementation and adds regression coverage for pagination, recycling, initial positioning, unread tracking, FullStory refs, and report scrolling.

This intentionally excludes the earlier work related to vertically centering an initially scrolled item.

Fixed Issues

$ #98994
$ #99202
PROPOSAL:

Tests

  1. Sign in with a high-traffic account and open a chat with a long message history.
  2. Verify the chat opens at the latest message and that the composer, unread marker, action badge, reactions, and message actions render normally.
  3. Scroll rapidly toward the oldest message, then continue scrolling after older messages load.
  4. Verify older messages load once per page, the visible message remains anchored, and messages do not overlap, flash blank, or jump to another position.
  5. Return to the latest message, send a message, and verify it appears at the bottom without moving the list to an unrelated position.
  6. Scroll away from the latest message and receive a message from another account.
  7. Verify the list does not move, the new-message indicator appears, and pressing the indicator returns to the latest message.
  8. Open a chat through a linked-message URL and verify the linked action is visible with the expected offset and highlight.
  9. Open a money request or transaction thread and verify its actions remain aligned to the top.
  10. Edit a message and open a PDF receipt preview, then verify the correct action stays in view as cells are recycled.
  11. Verify that no errors appear in the JS console.
  • Verify that no errors appear in the JS console

Offline tests

  1. Open a long chat while online so its actions are stored locally.
  2. Disconnect from the network, leave the chat, and reopen it.
  3. Verify the cached actions render at the correct position and scrolling does not produce overlaps or position jumps.
  4. Scroll to the oldest cached action and verify the list remains stable while no additional page can be fetched.
  5. Send a message while offline and verify the pending message appears at the bottom.
  6. Reconnect and verify the message sends and older-action pagination resumes without moving the visible content unexpectedly.

QA Steps

Same as Tests and Offline tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Screenshots and videos are not included yet because this PR is still a draft.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid creating the InvertedLegendList wrapper? Legend list intentionally doesn't provide an inverted mode, because Jay claims that it's stupid and we should just call .reverse on the data prop. If true, I agree it's simpler not to think about an inverted list 🤷🏼

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/FlatList/FlatList/index.ios.tsx 90.47% <100.00%> (ø)
src/hooks/useReportActionsListModel.ts 100.00% <ø> (ø)
src/hooks/useReportActionsScroll.ts 97.61% <100.00%> (-0.75%) ⬇️
src/hooks/useReportScrollManager/index.native.ts 90.47% <ø> (ø)
src/hooks/useReportScrollManager/index.ts 0.00% <ø> (ø)
src/pages/inbox/ActionListContext.tsx 94.44% <100.00%> (-5.56%) ⬇️
...c/pages/inbox/report/MoneyReportContentCreated.tsx 100.00% <100.00%> (ø)
...inbox/report/ReportActionCompose/useEditMessage.ts 86.95% <ø> (ø)
...rc/pages/inbox/report/ReportActionIndexContext.tsx 100.00% <100.00%> (ø)
src/pages/inbox/report/ReportActionItem.tsx 90.85% <100.00%> (+0.05%) ⬆️
... and 16 more
... and 32 files with indirect coverage changes

Keep positioned zero-sized anchors eligible for native scroll compensation when LegendList corrects estimated item sizes.
Enable native data and size anchoring, limit end-following to the latest page near its bottom, and remove competing message and draft scroll effects. Consume explicit live-tail requests after rendering instead of on a future viewport layout.

Keep the configured 1500px render window, correct the action-badge offset, and add regression coverage for scroll ownership and end-following.
@chrispader chrispader changed the title feat: migrate to LegendList PoC: Migrate to LegendList Sep 9, 2026
@chrispader

chrispader commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@roryabraham i've split this PR up into several smaller PRs that are going to be easier to merge:

Review order:

  1. Foundation: [LegendList 1/7] [No QA] feat: add LegendList foundation #100732 (8 files)
  2. Report actions: [WIP] [HOLD on #100884] [LegendList 4/7] feat: migrate report actions to chronological LegendList #100733 (40 files)
  3. Chat pagination loading: [HOLD on #100733] [LegendList 5/7] feat: add chat pagination loading indicators #100740) (13 files)
  4. Remaining FlashList consumers: [HOLD on #100740] [LegendList 6/7] feat: migrate remaining FlashList consumers to LegendList #100734) (108 files)
  5. Remaining FlatList consumers and restrictions: [HOLD on #100734] [LegendList 7/7] feat: migrate remaining FlatLists and restrict legacy imports #100736 (39 files)

The diff of PRs >2 include all the changes of the previous PRs.

@roryabraham

Copy link
Copy Markdown
Contributor

Thanks for doing that proactively @chrispader. Good call

@chrispader

chrispader commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

We can probably split up PRs 4 and 5 even more, at the moment these just replace all FlashList/FlatList usages with LegendList, but we can also merge these migrations in batches.

For now i'd say we focus on merging PRs 1-3 first 🙌🏼

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.

2 participants