Skip to content

Commit a84a5c0

Browse files
fix(web): prevent onMonitorClipboard from re-scheduling after iron-remote-desktop component destroys (#856)
1 parent b0e87a3 commit a84a5c0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

web-client/iron-remote-desktop/src/iron-remote-desktop.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
let lastSentClipboardData: ClipboardData | null = null;
7272
let lastClipboardMonitorLoopError: Error | null = null;
7373
74+
let componentDestroyed = false;
75+
7476
/* Firefox-specific BEGIN */
7577
7678
// See `ffRemoteClipboardData` variable docs below
@@ -185,12 +187,11 @@
185187
186188
// Called periodically to monitor clipboard changes
187189
async function onMonitorClipboard() {
188-
if (!document.hasFocus()) {
189-
setTimeout(onMonitorClipboard, CLIPBOARD_MONITORING_INTERVAL);
190-
return;
191-
}
192-
193190
try {
191+
if (!document.hasFocus()) {
192+
return;
193+
}
194+
194195
var value = await navigator.clipboard.read();
195196
196197
// Clipboard is empty
@@ -291,7 +292,9 @@
291292
lastClipboardMonitorLoopError = err;
292293
}
293294
} finally {
294-
setTimeout(onMonitorClipboard, CLIPBOARD_MONITORING_INTERVAL);
295+
if (!componentDestroyed) {
296+
setTimeout(onMonitorClipboard, CLIPBOARD_MONITORING_INTERVAL);
297+
}
295298
}
296299
}
297300
@@ -723,6 +726,7 @@
723726
724727
onDestroy(() => {
725728
window.removeEventListener('resize', resizeHandler);
729+
componentDestroyed = true;
726730
});
727731
</script>
728732

0 commit comments

Comments
 (0)