From 8e8dd6369654ae5b083d6559274397600925ec58 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 19 Aug 2025 09:52:01 -0700 Subject: [PATCH] fix: Initialize Vue node manager when first node is added to empty graph (#5086) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Initialize Vue node manager when first node is added to empty graph When Vue nodes are enabled and the graph starts empty (0 nodes), the node manager wasn't being initialized. This caused Vue nodes to not render until the setting was toggled off and on again. The fix adds a one-time event handler that listens for the first node being added to an empty graph and initializes the node manager at that point. Fixes the issue where Vue nodes don't render on initial page load when the setting is enabled. * fix: Add TODO comment for reactive graph mutations observer Added comment to indicate that the monkey-patching approach should be replaced with a proper reactive graph mutations observer when available. 🤖 Generated with Claude Code Co-Authored-By: Claude --------- Co-authored-by: Claude --- src/components/graph/GraphCanvas.vue | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index b49d501cdc..f972b8aa35 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -752,6 +752,32 @@ onMounted(async () => { comfyAppReady.value = true + // Set up a one-time listener for when the first node is added + // This handles the case where Vue nodes are enabled but the graph starts empty + // TODO: Replace this with a reactive graph mutations observer when available + if ( + transformPaneEnabled.value && + comfyApp.graph && + !nodeManager && + comfyApp.graph._nodes.length === 0 + ) { + const originalOnNodeAdded = comfyApp.graph.onNodeAdded + comfyApp.graph.onNodeAdded = function (node: any) { + // Restore original handler + comfyApp.graph.onNodeAdded = originalOnNodeAdded + + // Initialize node manager if needed + if (transformPaneEnabled.value && !nodeManager) { + initializeNodeManager() + } + + // Call original handler + if (originalOnNodeAdded) { + originalOnNodeAdded.call(this, node) + } + } + } + comfyApp.canvas.onSelectionChange = useChainCallback( comfyApp.canvas.onSelectionChange, () => canvasStore.updateSelectedItems()