Skip to content

[$250] Chat - Mentions copied from mweb are shown in clipboard but not pasted in android app #75991

Closed

Description

@jponikarchuk

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


Version Number: V9.2.63-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/TR-2158/folder/13176723/41237039/1035953069
Email or phone of affected tester (no customers): dreamnitethedragon+yydyd373@gmail.com
Issue reported by: Applause Internal Team
Device used: Redminote 10S Android 13
App Component: Chat Report View

Action Performed:

  1. Go to https://staging.new.expensify.com/home
  2. Open a chat
  3. Paste the text -
    *Jhehd
    @manager_mctest@expensify.com
    @hwhs@hs.com
    Hd

~@dreamnitethedragon+ebsjsjjsis@gmail.com

Hd

Hd*

@dreamnitethedragon+ebsjsjjsis@gmail.com~
4. Send the message
5. Copy the message from context menu
6. Launch app
7. Open a chat
8. Paste the message
9. Send the message

Expected Result:

Mentions copied from mweb are shown in clipboard so must be pasted in android app.

Actual Result:

Mentions copied from mweb are shown in clipboard but not pasted in android app.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021994481236967436315
  • Upwork Job ID: 1994481236967436315
  • Last Price Increase: 2025-11-28
  • Automatic offers:
    • situchan | Reviewer | 109721709
    • linhvovan29546 | Contributor | 109721711
Issue OwnerCurrent Issue Owner: @greg-schroeder

Activity

  1. added
    Daily
    Bug
    on Nov 25, 2025
  2. melvin-bot commented on Nov 25, 2025

    @melvin-bot

    Triggered auto assignment to @greg-schroeder (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. added
    External
    on Nov 28, 2025
  4. melvin-bot commented on Nov 28, 2025

    @melvin-bot
  5. changed the title [-]Chat - Mentions copied from mweb are shown in clipboard but not pasted in android app[/-] [+][$250] Chat - Mentions copied from mweb are shown in clipboard but not pasted in android app[/+] on Nov 28, 2025
  6. added
    Help Wanted
    on Nov 28, 2025
  7. melvin-bot commented on Nov 28, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @situchan (External)

  8. TaduJR commented on Nov 29, 2025

    @TaduJR
    Contributor

    Proposal

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

    When copying a message containing mentions from mobile web (mWeb) and pasting it into the Android app, the mentions are stripped and not pasted correctly.

    What is the root cause of that problem?

    Root Cause Flow:

    1. Copy (mWeb): Clipboard.setHtml() writes both text/html (with <mention-user> tags) and text/plain (markdown with @username) to clipboard

      const setHtml: SetHtml = (html: string, text: string) => {
      if (!html || !text) {
      return;
      }
      if (!canSetHtml()) {
      throw new Error('clipboard.write is not supported on this platform, thus HTML cannot be copied.');
      }
      if (CONST.BROWSER.SAFARI === Browser.getBrowser()) {
      // Safari sanitize "text/html" data before writing to the pasteboard when using Clipboard API,
      // whitespaces in the start of line are stripped away. We use the deprecated method to copy
      // contents as HTML and keep whitespaces in the start of line on Safari.
      // See https://webkit.org/blog/10855/async-clipboard-api/ for more details.
      setHTMLSync(html, text);
      } else {
      const htmlNonClosingTags = html
      .replaceAll(/<mention-report reportID="(\d+)" *\/>/gi, '<mention-report reportID="$1"></mention-report>')
      .replaceAll(/<mention-user accountID="(\d+)" *\/>/gi, '<mention-user accountID="$1"></mention-user>');
      navigator.clipboard.write([
      new ClipboardItem({
      /* eslint-disable @typescript-eslint/naming-convention */
      'text/html': new Blob([htmlNonClosingTags], {type: 'text/html'}),
      'text/plain': new Blob([text], {type: 'text/plain'}),
      }),
      ]);
      }
      };
      /**
      * Sets a string on the Clipboard object via react-native-web
      */
      const setString: SetString = (text) => {
      Clipboard.setString(text);
      };
      export default {

    2. Paste (Android): React Native's ReactEditText.onTextContextMenuItem() receives the paste action and delegates to super.onTextContextMenuItem(pasteAsPlainText)

      https://github.com/facebook/react-native/blob/49820611f5369ddbe7c758152d19ed899d296cbd/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L368-L371

    3. Android's TextView parses the HTML content and strips unknown tags like <mention-user> because it doesn't recognize them

    4. Result: Text arrives in the composer without mentions

    Logs:

    • Clipboard item.text: "*Jhehd\n@manager_mctest@expensify.com\n..." (correct)
    • Clipboard item.htmlText: "<mention-user accountid=\"18964612\">..." (correct)
    • What gets inserted: "Jhehd\n\n\nHd\n~..." (mentions stripped)

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

    Modify React Native's ReactEditText.onTextContextMenuItem() to manually insert item.text instead of delegating to Android's HTML parsing.

    Location to modify:

    https://github.com/facebook/react-native/blob/49820611f5369ddbe7c758152d19ed899d296cbd/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L368-L371

    Replace with:

    override fun onTextContextMenuItem(id: Int): Boolean {
        if (id != android.R.id.paste && id != android.R.id.pasteAsPlainText) {
            return super.onTextContextMenuItem(id)
        }
    
        val clipboardManager = getContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
        val clipData = clipboardManager.primaryClip
        if (clipData == null || clipData.itemCount == 0) {
            return super.onTextContextMenuItem(id)
        }
        val item = clipData.getItemAt(0)
    
        // Handle URI content (e.g., images, files)
        item.uri?.let { uri ->
            val type = getReactContext(this).contentResolver.getType(uri)
            if (type != null && type != ClipDescription.MIMETYPE_TEXT_PLAIN) {
                pasteWatcher?.onPaste(type, uri.toString())
                return true
            }
        }
    
        // Handle text content - always manually insert to bypass Android's HTML parsing
        item.text?.let { itemText ->
            pasteWatcher?.onPaste(ClipDescription.MIMETYPE_TEXT_PLAIN, itemText.toString())
            val start = maxOf(0, selectionStart)
            val end = maxOf(0, selectionEnd)
            text?.replace(minOf(start, end), maxOf(start, end), itemText)
            return true
        }
    
        return super.onTextContextMenuItem(id)
    }

    Implementation approach:

    1. Apply fix via patch-package for immediate resolution
    2. Submit PR to React Native for upstream fix

    What alternative solutions did you explore? (Optional)

    1. Modify mWeb clipboard to not set HTML - Would break rich paste between web browsers
    2. Use standard HTML tags instead of <mention-user> - Requires changes across all platforms
    3. Implement native useHtmlPaste hook for Android - More complex, requires native clipboard reading module
  9. melvin-bot commented on Dec 4, 2025

    @melvin-bot

    @situchan Huh... This is 4 days overdue. Who can take care of this?

  10. linhvovan29546 commented on Dec 5, 2025

    @linhvovan29546
    Contributor

    Proposal

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

    Mentions copied from mweb are shown in clipboard but not pasted in android app.

    What is the root cause of that problem?

    This issue occurs on Android due to the custom patch applied in our app:

    + override fun onTextContextMenuItem(id: Int): Boolean {

    This patch modifies TextInput to support handling pasted images: #41239
    When pasting text copied from mWeb, the id received is android.R.id.paste.
    Our patch treats this as android.R.id.pasteAsPlainText and triggers custom paste logic.
    However, because the pasted content is plain text, it does not satisfy certain conditions in the custom logic, and we fall through to:
    + // Don't return - let the system proceed with default text pasting behavior


    The problem arises because we pass the original id back to the system. This leads the system to process the wrong id, causing the paste bug

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

    We should update the patch so that we return modifiedId instead of id


    return super.onTextContextMenuItem(modifiedId)
    The reason we should use modifiedId is that same as the original code from before the patch was applied
    https://github.com/facebook/react-native/blob/95cc1e76756ea0d67bfe20be35aff99c4028f2f2/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L370-L373

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  11. 11 remaining items

  12. added
    Reviewing
    Weekly
    and removed
    Daily
    on Dec 7, 2025
  13. linhvovan29546 commented on Dec 17, 2025

    @linhvovan29546
    Contributor

    @greg-schroeder The PR was deployed to production on Dec 11, 2025, the automation bot failed. #76930 (comment)

  14. linhvovan29546 commented on Dec 19, 2025

    @linhvovan29546
    Contributor

    Hi @yuwenmemon @greg-schroeder please remove the Reviewing label and bump to Daily as payment is due

  15. added
    Awaiting Payment
    and removed
    Reviewing
    on Dec 19, 2025
  16. greg-schroeder commented on Dec 19, 2025

    @greg-schroeder
    Contributor
  17. situchan commented on Dec 19, 2025

    @situchan
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/47203/changes#r2635874313

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue:

    Regression Test Proposal

    Test case seems already exist
    https://test-management.browserstack.com/projects/2219752/test-runs/TR-2158/folder/13176723/41237039/1035953069

  18. situchan commented on Dec 19, 2025

    @situchan
    Contributor

    This is ready for payment

  19. yuwenmemon commented on Dec 19, 2025

    @yuwenmemon
    Contributor

    Thanks! cc @greg-schroeder

  20. greg-schroeder commented on Dec 22, 2025

    @greg-schroeder
    Contributor

    Paid via Upwork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugExternalWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions