core: better `ClipboardSnapshot` race condition handling
Opened this issue · 0 comments
Clipboard Entry
upsertion logic is designed around supporting the following behavior:
- Clicking on a clipboard entry in the popup should not upsert an
Entry
. - Organically copying content outside of the popup that's different from the currently copied content should upsert an
Entry
.
There is currently a race condition between the updatedAt
field of the ClipboardSnapshot
object, set when the user copies a clipboard history list entry in the popup, and the timestamp of the sampled clipboard content provided in the offscreen script. This causes the logic for determining whether to upsert an Entry
(link) to fail if the offscreen script samples the clipboard content between when ClipboardSnapshot
is updated and the content the user is trying to copy is written to the clipboard (link). The band-aid fix for this is making the recorded timestamp provided by the offscreen script 1 second in the past (link). The race condition doesn't show up so long as updating the clipboard snapshot takes less than a second (which only happens when ~8mb of data is stored).
This fix is acceptable for now but is pretty flaky. Ideas for a better implementation of this behavior are very much welcome!