You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix Invertedprop on the FlatListcomponent with a RN Patch #3381
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.
Pasting - When pasting copied text from multiple e.cash messages, it's out of order
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
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.
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 ?
Agree with @azimgd I think these are separate issues. Per Slack (link) We have this two existing issues: #5142Copying messages with markdown via CTRL + C does not keep formatting (moving along) #5125Markdown - 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
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:
Scroll container (VirtualizedList/index.js) applies transform: scaleY(-1) to the entire list, flipping it upside down.
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.
src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx:724-762 — Context menu copy message action
Implementation Notes
There are already 6+ react-native-web patches for VirtualizedList behavior (scroll, overscroll, nested lists). Any Option B changes must be compatible with these.
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.
@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
Copying text from multiple chats working correctly
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
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.
Copying text from multiple chats working correctly
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.
Activity
MelvinBot commentedon Jun 4, 2021
Triggered auto assignment to @kadiealexander (
AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.MelvinBot commentedon Jun 4, 2021
Triggered auto assignment to @thienlnam (
Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.mallenexpensify commentedon Jun 4, 2021
@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
MelvinBot commentedon Jun 7, 2021
Triggered auto assignment to @trjExpensify (
External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.thienlnam commentedon Jun 7, 2021
@mallenexpensify Sorry, was OOO but issue looks good and we can have a contributor start working on it. Nice detailed write-up!
169 remaining items
mallenexpensify commentedon Dec 24, 2021
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.
quinthar commentedon Dec 24, 2021
azimgd commentedon Dec 24, 2021
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 ?
mallenexpensify commentedon Dec 27, 2021
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
mallenexpensify commentedon Dec 28, 2021
@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.
marcaaron commentedon Jan 4, 2022
cc @kidroca as we are discussing a possible regression here https://expensify.slack.com/archives/C01GTK53T8Q/p1641320742022500?thread_ts=1641315371.490700&cid=C01GTK53T8Q
kidroca commentedon Jan 5, 2022
Added some more comments on slack to explain what's happening and why
MelvinBot commentedon Mar 9, 2026
🔍 Issue Analysis
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 passesinverted={true}to React Native's FlatList. On web, react-native-web implements this inversion via CSStransform: scaleY(-1)applied at two levels:VirtualizedList/index.js) appliestransform: scaleY(-1)to the entire list, flipping it upside down.VirtualizedListCellRenderer.js) appliesflexDirection: 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 theSelectionScraper(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 withflexDirection: column-reverseon 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 atpatches/react-native-web+0.19.13+0XX+fix-inverted-selection.patchmodifying 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)
direction: rtlor CSSwriting-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:
ReportActionsListrenderssortedVisibleReportActions(newest first) viaInvertedFlatList(src/pages/inbox/report/ReportActionsList.tsx:863)InvertedFlatListwraps React Native's FlatList withinverted={true}transform: scaleY(-1)to the scroll container and each cell[newest, ..., oldest](top to bottom)[oldest, ..., newest](top to bottom, due to CSS transform)window.getSelection()returns content in DOM order: newest firstSelectionScraper.getCurrentSelection()reads this and writes to clipboard as-isEvidence Chain
InvertedFlatListpassesinvertedprop → confirmed atsrc/components/FlatList/InvertedFlatList/index.tsx:49scaleY(-1)applied → confirmed inreact-native-web/dist/vendor/react-native/VirtualizedList/index.jsstyles definitionsrc/libs/SelectionScraper/index.tsuseCopySelectionHelperpasses selection through without modification → confirmed atsrc/hooks/useCopySelectionHelper.tsRelevant Code
src/components/FlatList/InvertedFlatList/index.tsx— InvertedFlatList componentsrc/libs/SelectionScraper/index.ts— Selection reading and HTML extractionsrc/hooks/useCopySelectionHelper.ts— Ctrl+C handlingnode_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js:2128-2131— scaleY(-1) stylesnode_modules/react-native-web/src/vendor/react-native/VirtualizedList/VirtualizedListCellRenderer.js:201-246— Cell-level inversion stylessrc/pages/inbox/report/ContextMenu/ContextMenuActions.tsx:724-762— Context menu copy message actionImplementation Notes
CellRendererComponent(src/components/FlatList/InvertedFlatList/CellRendererComponent.tsx) setszIndex: -indexwhich may further complicate selection behavior.userSelectTextstyle (src/pages/inbox/report/comment/TextCommentFragment.tsx:126).Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.mallenexpensify commentedon Mar 9, 2026
@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
Reopened this cuz Andrew linked to it as the likely culprit here
marcaaron commentedon Mar 9, 2026
This issue feels extremely stale.
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.
mallenexpensify commentedon Mar 9, 2026
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