Skip to content

[LegendList 5/12] refactor: prepare report list refs and recycled row state - #104978

Merged
roryabraham merged 3 commits into
Expensify:mainfrom
margelo:@chrispader/refactor/legend-list-row-preparation
Oct 29, 2026
Merged

roryabraham merged 3 commits into
Expensify:mainfrom
margelo:@chrispader/refactor/legend-list-row-preparation

Conversation

@chrispader

@chrispader chrispader commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Message rows can be reused for another action, and the shared list ref still describes a legacy FlatList. This PR adds a common ref contract and prepares row and preview state for reuse. It also lets money reports finish edit scrolling after the list layout commits.

@roryabraham @dmkt9

Explanation of Change

This is layer 5 of the twelve-part LegendList series, extracted from #100733. It is independent of layer 4. The main chat continues to use inverted FlashList; layer 9 introduces LegendList rendering. A temporary type export keeps the existing FlashList wrapper compatible until that migration removes it. Closing an edit in the main chat now calls the scroll manager's scrollToBottom instead of scrollToIndex(0), so on web the list jumps to the newest message instead of animating.

Review and merge order: twelve-part LegendList rollout. Layers 6 to 8 are independent preparations; merge all three before layer 9.

Fixed Issues

$ #98994

Part of the migration split from #98270. No approved proposal is linked.

Tests

All platforms means desktop web, mobile web, Android, and iOS.

All platforms, attachment previews after scrolling

  1. Open a chat with scrollable history.
  2. Send a portrait image.
  3. Send a landscape image.
  4. Send a PDF.
  5. Scroll until those attachments are off-screen.
  6. Scroll back to them. Each attachment preview should match its file and keep the correct proportions.
  7. Open the PDF. The document you sent should open.

All platforms, switching between expenses

Use an expense report containing two expenses with different amounts and receipt images.

  1. Open the expense report.
  2. Open the first expense. Its amount and receipt image should be visible.
  3. Return to the report's expense list.
  4. Open the second expense. Its amount and receipt should belong to the second expense, without showing details from the first.

All platforms, save, cancel, and delete an expense-report comment

  1. Open an expense report where you can leave comments.
  2. Send the comment one.
  3. Open that comment's action menu.
  4. Choose Edit.
  5. Replace the text with two.
  6. Save the edit. The newest comment should remain visible without a blank area at the bottom.
  7. Open the edited comment's action menu.
  8. Choose Edit.
  9. Change the comment text.
  10. Cancel the edit. The comment should still say two and remain visible at the bottom.
  11. Open that comment's action menu.
  12. Choose Edit.
  13. Clear the comment text.
  14. Save the empty edit. A delete confirmation should appear.
  15. Confirm deletion. The list should show its newest remaining message.

All platforms, edit the newest chat message

  1. Open a chat.
  2. Send a short message.
  3. Open that message's action menu.
  4. Choose Edit.
  5. Change the message text.
  6. Save the edit. The updated message should remain visible at the bottom.
  • Verify that no errors appear in the JS console

Offline tests

All platforms, save a cached comment offline

  1. Open an expense report where you can leave comments while online.
  2. Send the comment Offline edit.
  3. Disconnect the internet.
  4. Open that comment's action menu.
  5. Choose Edit.
  6. Change the comment text.
  7. Save the edit. The updated comment should remain visible.
  8. Reconnect the internet. The edited comment should remain correct.

All platforms, attachment previews offline

  1. Open a chat containing an image while online.
  2. Open the image.
  3. Close the image viewer.
  4. Disconnect the internet.
  5. Scroll the image off-screen.
  6. Scroll back to it. Its preview should not be replaced by another attachment.
  7. Reconnect the internet.

QA Steps

Run the All platforms cases and the blocks for the platform being tested, including 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 verified any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

iOS: Native

All platforms, edit the newest chat message

pr5-ios-newest-chat-edit-upload.mp4

Cold chat open and initial loading

FlashList is on the left and LegendList is on the right. FlashList leaves the report body blank during loading; LegendList shows the report-action skeleton before messages appear.

LegendListLoadingSkeletonVsFlashList.mp4

Cold expense-chat open

FlashList is on the left and LegendList is on the right. Both progress from the loading skeleton to an expense preview and its surrounding report actions.

ExpenseChatCold.mp4

Warm expense-chat open

FlashList is on the left and LegendList is on the right. Both open the cached expense preview and report actions from the inbox.

ExpenseChatWarm.mp4

Warm chat open

Side-by-side opens of the same cached chat, ending on the same report-action history. The implementations are not labeled in this recording.

LegendListWarmReportOpen.mp4
Android: Native

All platforms, attachment previews after scrolling

attachments.mp4

All platforms, switching between expenses

reports.mp4

All platforms, save, cancel, and delete an expense-report comment

longedit.mp4

All platforms, edit the newest chat message

edit1.mp4
MacOS: Chrome / Safari

All platforms, attachment previews after scrolling

Screen.Recording.2026-10-28.at.10.45.11.mov

All platforms, switching between expenses

Screen.Recording.2026-10-28.at.11.14.51.mov

All platforms, save, cancel, and delete an expense-report comment

Screen.Recording.2026-10-28.at.10.48.19.mov

All platforms, edit the newest chat message

Screen.Recording.2026-10-28.at.10.49.10.mov

Share the report list imperative contract while retaining a compatibility export for inverted FlashList. Keep row-local preview state tied to its action and let money-report edit scroll requests survive until the list commits its layout.

Co-authored-by: Codex <noreply@openai.com>
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...equestReportView/MoneyRequestReportActionsList.tsx 97.32% <100.00%> (+0.11%) ⬆️
...stReportView/MoneyRequestReportTransactionList.tsx 93.44% <100.00%> (+0.03%) ⬆️
...equestReportView/MoneyRequestReportUnifiedList.tsx 70.19% <100.00%> (+0.19%) ⬆️
...nents/ReportActionItem/ReceiptPDFOverlay/index.tsx 93.15% <100.00%> (ø)
src/components/ThumbnailImage.tsx 98.24% <100.00%> (+3.60%) ⬆️
src/hooks/useReportScrollManager/index.native.ts 92.59% <100.00%> (+3.70%) ⬆️
src/pages/inbox/ActionListContext.tsx 100.00% <100.00%> (ø)
...c/pages/inbox/report/MoneyReportContentCreated.tsx 100.00% <100.00%> (ø)
...inbox/report/ReportActionCompose/useEditMessage.ts 95.23% <100.00%> (ø)
...rc/pages/inbox/report/ReportActionIndexContext.tsx 100.00% <100.00%> (ø)
... and 6 more
... and 8 files with indirect coverage changes

@chrispader

Copy link
Copy Markdown
Contributor Author

@MelvinBot request review from @roryabraham and @dmkt9 and assign them here.

@MelvinBot

Copy link
Copy Markdown
Contributor

Done. I requested reviews from roryabraham and dmkt9 and assigned them to this PR.


view run

Keep shared list refs compatible with main's live-range badge tracking.

Co-authored-by: Codex <noreply@openai.com>
@chrispader
chrispader marked this pull request as ready for review October 27, 2026 17:44
@chrispader
chrispader requested review from a team as code owners October 27, 2026 17:44
@melvin-bot
melvin-bot Bot requested review from trjExpensify and removed request for a team October 27, 2026 17:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

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-10-27T18:23:19.559893Z
We couldn’t complete this review. Comment @codex review to try again.
6c9c0ef Draft marked ready
ℹ️ 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.

@melvin-bot
melvin-bot Bot requested review from mollfpr and removed request for a team October 27, 2026 17:45
@melvin-bot

melvin-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

@mollfpr Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@trjExpensify

Copy link
Copy Markdown
Contributor

PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself.

@trjExpensify
trjExpensify removed their request for review October 27, 2026 20:01
@chrispader

Copy link
Copy Markdown
Contributor Author

@dmkt9 feel free to review this already independently of #104977, this PR does not depend on it! 🙌🏼

Preserve row identity resets alongside expanded system-message focus.

Co-authored-by: Codex <noreply@openai.com>
fullPolicySnapshot: report?.policyID && fullPolicySnapshotLastModified ? {policyID: report.policyID, lastModified: fullPolicySnapshotLastModified} : undefined,
});

const [editScrollRequestID, setEditScrollRequestID] = useState(0);

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.

I'm pretty confused by this variable name. What's an "edit scroll request"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renaming this in #100733

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Chris's AI teammate here. 🤖

Renamed it to scrollToNewestRequestID in #100733, with lastHandledScrollToNewestRequestIDRef tracking which request was handled. It requests a scroll to the newest action after closing its editor. I also added a comment explaining why FlashList must measure the updated rows before scrolling.

@dmkt9

dmkt9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review: no blocking issues

The refactor looks correct. I found no bugs, and all CI checks pass except the reviewer checklist. The notes below are small follow-ups, not blockers.

What I verified

  • Edit scroll timing. stopEditing() is local React state, so it lands in the same commit as the scroll request. FlashList 2.3.2 runs onCommitLayoutEffect only after row sizes settle: if a row's height changed, it re-renders and measures again first. The request therefore fires after the editor row has been measured, and the ref guard makes sure it fires once.
  • useRecyclingState outside LegendList. With no LegendList context it reads empty values and never throws. Because isRecycling defaults to false, today's FlashList rows still use useState.
  • Main chat edit close. scrollToBottom() calls scrollToIndex({index: 0, animated: false}) on web and native, which matches the PR description.

Suggestions

  1. Rename the edit-scroll state (MoneyRequestReportActionsList.tsx:253-264). This also answers roryabraham's question. Names like pendingScrollToNewestID and lastHandledScrollToNewestIDRef would say what the code does. Add a one-line comment explaining that the scroll waits for FlashList's layout commit so the closed editor's new height is measured first.
  2. Document the isRecycling contract (ReportActionIndexContext.tsx:36-40). LegendList's setter does nothing when there is no container context, because triggerLayout is undefined. If a future list sets isRecycling outside a LegendList container, every state setter here would fail silently. A short comment would prevent that.
  3. Optional: keep useState in ReceiptPDFOverlay (ReceiptPDFOverlay/index.tsx:130). failedURL already resets on reuse because hasFailed compares it with the current fileURL. The hook swap does no harm, but it isn't needed.

view run

@dmkt9

dmkt9 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app 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 verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
chrome.mp4

@dmkt9 dmkt9 left a comment

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.

LGTM

@melvin-bot
melvin-bot Bot requested a review from roryabraham October 29, 2026 04:55
@roryabraham
roryabraham merged commit dfd7f61 into Expensify:main Oct 29, 2026
38 of 40 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.26-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR is an internal list-refactor (shared list ref types, row and preview state reset for reuse, and edit-scroll timing), so it adds no new feature and doesn't change any workflow, label, or behavior described in a help article.


view run

@chrispader chrispader changed the title [LegendList 5/9] refactor: prepare report list refs and recycled row state [LegendList 5/12] refactor: prepare report list refs and recycled row state Oct 30, 2026
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.

6 participants