Skip to content

Fix Invertedprop on the FlatListcomponent with a RN Patch  #3381

Closed

Description

@mallenexpensify

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Expected Result:

  • When copying text in e.cash that when you highlight lines of text, including across multiple messages, that the text is highlighted in order from top to bottom or bottom to top.
  • When pasting text that has been copied in e.cash, that it shows up in the correct order.

Actual Result:

  • Copying is sporadic and 'jumps around' when you highlight text over multiple messages. View video example at https://www.screencast.com/t/AzFBzTDs3ESm
    image

  • Pasting - When pasting copied text from multiple e.cash messages, it's out of order

image

Action Performed:

  • Open Web or Desktop
  • Create multiple messages in a test account (ie. 1 , click enter, 2, click enter, etc)
  • Attempt to copy the multiple messages, observe you can't easily copy them in the correct order.
  • Once you've been able to capture some of the multiple messages, paste in the compose box
  • Observe the messages paste out of order.

Workaround:

The work around is to copy single messages at a time.

Platform:

Where is this issue occurring?

Web ✅
iOS
Android
Desktop App ✅
Mobile Web

Version Number: Version 1.0.62 (the issue has been happening since we launched)
Logs: N/A
Notes/Photos/Videos:
The deliverable is to fix the core issue (Copying and Pasting on Web and Desktop are weird and out of order). The PR should be submitted against our RN fork (Expensify/react-native).
A lot of discussion about this issue is here for additional context #1341

Expensify/Expensify Issue URL: From months ago https://github.com/Expensify/Expensify/issues/142340#

View all open jobs on Upwork

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    AutoAssignerTriage
    on Jun 4, 2021
  2. MelvinBot commented on Jun 4, 2021

    @MelvinBot
    Contributor

    Triggered auto assignment to @kadiealexander (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

  3. removed
    AutoAssignerTriage
    on Jun 4, 2021
  4. MelvinBot commented on Jun 4, 2021

    @MelvinBot
    Contributor

    Triggered auto assignment to @thienlnam (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

  5. mallenexpensify commented on Jun 4, 2021

    @mallenexpensify
    ContributorAuthor

    @thienlnam we plan to have a contributor work on this, can you review to ensure I didn't miss anything then add the External label? Thanks

  6. added
    External
    on Jun 7, 2021
  7. MelvinBot commented on Jun 7, 2021

    @MelvinBot
    Contributor

    Triggered auto assignment to @trjExpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

  8. thienlnam commented on Jun 7, 2021

    @thienlnam
    Contributor

    @mallenexpensify Sorry, was OOO but issue looks good and we can have a contributor start working on it. Nice detailed write-up!

  9. removed their assignment
    on Jun 8, 2021
  10. 169 remaining items

  11. mallenexpensify commented on Dec 24, 2021

    @mallenexpensify
    ContributorAuthor

    Thanks for the thorough breakdown @thienlnam . Thanks for all the help @azimgd !
    I added the payment to my calendar for the 28th (assuming no regressions). I'll update here once payment is issued.

  12. quinthar commented on Dec 24, 2021

    @quinthar
    Contributor
  13. azimgd commented on Dec 24, 2021

    @azimgd
    Contributor

    Hey David,
    I was indeed able to reproduce your issue, but I wouldn't count that as a regression since this exact behavior existed in the older/pre-merge version of the app. Tested from this commit e230e7e

    Can we actually create a new task for this one as it's related to formatting ?

  14. mallenexpensify commented on Dec 27, 2021

    @mallenexpensify
    ContributorAuthor

    Agree with @azimgd I think these are separate issues. Per Slack (link) We have this two existing issues:
    #5142 Copying messages with markdown via CTRL + C does not keep formatting (moving along)
    #5125 Markdown - Copied text (with markdown) does not show the formatting when pasted (waiting for comment on up-to-date plan, I think @parasharrajat is looking into that)

    When/where needed, let's keep creating singular issue til we get all the copy/issues resolved

  15. mallenexpensify commented on Dec 28, 2021

    @mallenexpensify
    ContributorAuthor

    @azimgd paid $20,500 per Jack's breakdown above.

    Thanks for seeing this one through @azimgd , it's been the largest external issue we've ever had, feels realllly good to close this.

  16. marcaaron commented on Jan 4, 2022

    @marcaaron
    Contributor
  17. kidroca commented on Jan 5, 2022

    @kidroca
    Contributor

    Added some more comments on slack to explain what's happening and why

  18. added
    Melvin Triage
    on Mar 9, 2026
  19. MelvinBot commented on Mar 9, 2026

    @MelvinBot
    Contributor

    🔍 Issue Analysis

    Note: This issue is currently CLOSED, but the underlying technical mechanism described below still exists in the codebase. The transform: scaleY(-1) approach for list inversion persists in the current react-native-web VirtualizedList implementation.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When selecting text across multiple chat messages on Web/Desktop and pasting, the text appears out of order. Additionally, the text selection highlight "jumps around" erratically when dragging across messages, making it difficult to select the intended content.

    What is the root cause of that problem?

    The chat message list uses InvertedFlatList (src/components/FlatList/InvertedFlatList/index.tsx:49), which passes inverted={true} to React Native's FlatList. On web, react-native-web implements this inversion via CSS transform: scaleY(-1) applied at two levels:

    1. Scroll container (VirtualizedList/index.js) applies transform: scaleY(-1) to the entire list, flipping it upside down.
    2. Each cell (VirtualizedListCellRenderer.js) applies flexDirection: column-reverse + transform: scaleY(-1) to flip each cell back to readable orientation.

    This double-flip makes text visually readable, but the DOM order remains newest-message-first (index 0 = newest). The browser's window.getSelection() API returns content in DOM order, not visual order. Since the SelectionScraper (src/libs/SelectionScraper/index.ts) faithfully reads from the Selection API without any reordering logic, pasted text ends up reversed (newest first instead of chronological).

    The jumpy selection behavior occurs because the browser's text selection algorithm works with DOM coordinates, not accounting for the CSS scaleY(-1) transform that visually reverses the element positions.

    What changes do you think we should make in order to solve the problem?

    There are two viable approaches:

    Option A (Recommended): Modify SelectionScraper.getHTMLOfSelection() to detect when the selection spans multiple messages inside an inverted FlatList, and reverse the order of the message blocks before returning the HTML. This would fix the paste ordering issue. However, it would not fix the jumpy selection highlight behavior, which is a browser-level CSS transforms limitation.

    Option B (More comprehensive): Replace the transform: scaleY(-1) inversion mechanism with flexDirection: column-reverse on the scroll container in the react-native-web patches. This would make the DOM order match the visual order, fixing both the selection highlighting and paste ordering issues. This would require a new react-native-web patch at patches/react-native-web+0.19.13+0XX+fix-inverted-selection.patch modifying the VirtualizedList styles. This is a larger change that would need careful testing of scroll behavior, maintainVisibleContentPosition, and the existing 6+ patches to VirtualizedList.

    What alternative solutions did you explore? (Optional)

    • Intercepting the copy event at the browser level to reverse content before it hits the clipboard — fragile and doesn't fix the visual selection jump issue.
    • Using direction: rtl or CSS writing-mode — these don't apply to vertical ordering and introduce their own issues.
    Detailed Investigation

    Root Cause Analysis

    The data flow that leads to the bug:

    1. ReportActionsList renders sortedVisibleReportActions (newest first) via InvertedFlatList (src/pages/inbox/report/ReportActionsList.tsx:863)
    2. InvertedFlatList wraps React Native's FlatList with inverted={true}
    3. react-native-web applies transform: scaleY(-1) to the scroll container and each cell
    4. DOM order: [newest, ..., oldest] (top to bottom)
    5. Visual order: [oldest, ..., newest] (top to bottom, due to CSS transform)
    6. User selects text visually from top (oldest) to bottom (newest)
    7. window.getSelection() returns content in DOM order: newest first
    8. SelectionScraper.getCurrentSelection() reads this and writes to clipboard as-is
    9. Pasted text: newest message first (wrong order)

    Evidence Chain

    Relevant Code

    • src/components/FlatList/InvertedFlatList/index.tsx — InvertedFlatList component
    • src/libs/SelectionScraper/index.ts — Selection reading and HTML extraction
    • src/hooks/useCopySelectionHelper.ts — Ctrl+C handling
    • node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js:2128-2131 — scaleY(-1) styles
    • node_modules/react-native-web/src/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.js:201-246 — Cell-level inversion styles
    • src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx:724-762 — Context menu copy message action

    Implementation Notes


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  20. mallenexpensify commented on Mar 9, 2026

    @mallenexpensify
    ContributorAuthor

    @marcaaron is any of the info Melvin provided helpful? And/or are there any reasons to revisit this? (in a new issue since this one is a beast). Asking cuz I'm hoping we could fix, at least, two known bugs

    1. Copying text from multiple chats working correctly
    2. Scroll being more smooth (if you scroll up slowly in #social with your trackpad it stutters.

    Reopened this cuz Andrew linked to it as the likely culprit here

  21. marcaaron commented on Mar 9, 2026

    @marcaaron
    Contributor

    This issue feels extremely stale.

    And/or are there any reasons to revisit this?

    I'd recommend assessing the original problem statement. Let's test to see if we still have that problem for issues like these. If not, then close them.

  22. mallenexpensify commented on Mar 9, 2026

    @mallenexpensify
    ContributorAuthor
    1. Copying text from multiple chats working correctly
    2. Scroll being more smooth (if you scroll up slowly in #social with your trackpad it stutters.

    These both still exist (and there are likely dedicated, outdated, issues for both). I wanted to tag Melvin here since there's so much history and context. I'll close for now, if anyone gleams anything valuable in Melvin's post above, please comment/reopen.

    2026-03-09_11-36-58.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

EngineeringExternalMelvin TriageWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions