TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Copy-paste broken on WhatsApp on Firefox

2 pointsby arch1ealmost 2 years ago

1 comment

rolphalmost 2 years ago
&gt;&gt; Egrodo commented Aug 17, 2023 •<p>Thanks for the report! I confirmed that this is a recent regression and spent an afternoon looking into it. The fix has landed and should be deployed on Monday :)<p>This was an interesting bug so I figured I&#x27;d explain the fix below for anyone interested:<p>the issue boiled down to an async wrapper we had over the DataTransfer constructor that we were using to check osme other things before handling the DT. We were doing something like:<p>const data = event.clipboardData;<p>let text = data.getData(MIMETYPE_1); await SomePromise(); if (text == null) { text = data.getData(MIMETYPE_2); } ...<p>In this case MIMETYPE_1 was set when copying things from within WAWeb, and MIMETYPE_2 was text&#x2F;plain, so basically any text copied from outside the app fell into this.<p>The issue was that by calling await we were switching into a different callstack, thus (presumably) triggering Firefox&#x27;s more aggressive garbage collection to forget the contents of the data object. So when it came to calling data.getData the second time, the contents of the data object were missing, and we&#x27;d overwrite text with nullish. This is unintuitive since we didn&#x27;t switch lexical scopes, but I suppose Firefox considers DataTransfer objects more expensive than other browsers?<p>The fix was to run both checks at the same time before calling any async code so the data would be preserved:<p>Aka:<p>const data = event.clipboardData;<p>let textOne = data.getData(MIMETYPE_1); let textTwo = data.getData(MIMETYPE_2); await SomePromise(); let text = textOne; if (text == null) { text = textTwo; } ... &lt;&lt;