Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/renderer/extensions/vueNodes/components/LGraphNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@

<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { computed, nextTick, onErrorCaptured, onMounted, ref, watch } from 'vue'
import {
computed,
nextTick,
onErrorCaptured,
onMounted,
onUnmounted,
ref,
watch
} from 'vue'
import { useI18n } from 'vue-i18n'

import type { VueNodeData } from '@/composables/graph/useGraphNodeManager'
Expand All @@ -153,7 +161,9 @@ import { useSettingStore } from '@/platform/settings/settingStore'
import { useTelemetry } from '@/platform/telemetry'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions'
import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations'
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
import { LayoutSource } from '@/renderer/core/layout/types'
import SlotConnectionDot from '@/renderer/extensions/vueNodes/components/SlotConnectionDot.vue'
import { useNodeEventHandlers } from '@/renderer/extensions/vueNodes/composables/useNodeEventHandlers'
import { useNodePointerInteractions } from '@/renderer/extensions/vueNodes/composables/useNodePointerInteractions'
Expand Down Expand Up @@ -302,6 +312,45 @@ const handleContextMenu = (event: MouseEvent) => {

onMounted(() => {
initSizeStyles()
setupLitegraphResizeSync()
})

const mutations = useLayoutMutations()

let originalOnResize: ((size: [number, number]) => void) | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Cleanup won't restore if original handler was undefined.

If node.onResize was originally undefined, originalOnResize captures that value, but the condition originalOnResize !== undefined prevents restoration. The node retains the custom handler with stale closure references.

🐛 Proposed fix using a sentinel flag
-let originalOnResize: ((size: [number, number]) => void) | undefined
+let originalOnResize: ((size: [number, number]) => void) | undefined
+let hasModifiedOnResize = false

 function setupLitegraphResizeSync() {
   const node = lgraphNode.value
   if (!node) return

   originalOnResize = node.onResize
+  hasModifiedOnResize = true

   node.onResize = (newSize: [number, number]) => {
     // ... existing logic
   }
 }

 onUnmounted(() => {
   const node = lgraphNode.value
-  if (node && originalOnResize !== undefined) {
+  if (node && hasModifiedOnResize) {
     node.onResize = originalOnResize
   }
 })

Also applies to: 349-354

🤖 Prompt for AI Agents
In @src/renderer/extensions/vueNodes/components/LGraphNode.vue at line 320,
originalOnResize captures undefined and the current cleanup checks
originalOnResize !== undefined so it never restores the handler when original
was undefined; fix by always restoring the original value (remove the !==
undefined guard) — i.e., in the effect cleanup assign node.onResize =
originalOnResize unconditionally (references: originalOnResize and node.onResize
in the cleanup block around the effect that installs the custom onResize), or
alternatively track existence with a boolean sentinel (e.g.,
hadOriginalOnResize) set when saving originalOnResize and use that sentinel to
decide restoration.


/**
* Set up sync from litegraph node.setSize() to layoutStore.
* This handles extensions like KJNodes that programmatically resize nodes.
*/
function setupLitegraphResizeSync() {
const node = lgraphNode.value
if (!node) return

originalOnResize = node.onResize

node.onResize = (newSize: [number, number]) => {
originalOnResize?.(newSize)

mutations.setSource(LayoutSource.Canvas)
mutations.resizeNode(nodeData.id, {
width: newSize[0],
height: newSize[1]
})

const el = nodeContainerRef.value
if (el && !isCollapsed.value) {
el.style.setProperty('--node-width', `${newSize[0]}px`)
el.style.setProperty('--node-height', `${newSize[1]}px`)
}
}
}

onUnmounted(() => {
const node = lgraphNode.value
if (node && originalOnResize !== undefined) {
node.onResize = originalOnResize
}
})

/**
Expand Down
Loading