From be37966b45673014b2d6a845913b924d7ec39c97 Mon Sep 17 00:00:00 2001 From: diodiogod Date: Wed, 14 Jan 2026 16:11:22 -0300 Subject: [PATCH] Add DOM connection check to prevent capturing events in subgraphs Ensure the canvas element is actually connected to the DOM before handling paste events. This prevents LayerForge from capturing paste events when navigating in subgraphs where the canvas is not visible. Adds check for canvas.isConnected and document.body.contains() to verify the canvas is part of the active DOM tree. --- js/CanvasInteractions.js | 4 ++++ src/CanvasInteractions.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/js/CanvasInteractions.js b/js/CanvasInteractions.js index c3432d1..24056a6 100644 --- a/js/CanvasInteractions.js +++ b/js/CanvasInteractions.js @@ -1165,6 +1165,10 @@ export class CanvasInteractions { } } async handlePasteEvent(e) { + // Check if canvas is connected to DOM and visible + if (!this.canvas.canvas.isConnected || !document.body.contains(this.canvas.canvas)) { + return; + } const shouldHandle = this.canvas.isMouseOver || this.canvas.canvas.contains(document.activeElement) || document.activeElement === this.canvas.canvas; diff --git a/src/CanvasInteractions.ts b/src/CanvasInteractions.ts index e636214..3476166 100644 --- a/src/CanvasInteractions.ts +++ b/src/CanvasInteractions.ts @@ -1354,6 +1354,10 @@ export class CanvasInteractions { } async handlePasteEvent(e: ClipboardEvent): Promise { + // Check if canvas is connected to DOM and visible + if (!this.canvas.canvas.isConnected || !document.body.contains(this.canvas.canvas)) { + return; + } const shouldHandle = this.canvas.isMouseOver || this.canvas.canvas.contains(document.activeElement) ||