Skip to content

Commit 80d58dd

Browse files
DrJKLampcode-com
andcommitted
refactor: move composables and watchers outside onMounted
- Move useCopy, usePaste, useWorkflowAutoSave to top level - Move locale change watcher outside onMounted with proper guard - Move litegraph:set-graph event listener to top level Amp-Thread-ID: https://ampcode.com/threads/T-019bf94d-b905-77ee-965d-a9c2a327dc2a Co-authored-by: Amp <amp@ampcode.com>
1 parent 3c0b227 commit 80d58dd

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/components/graph/GraphCanvas.vue

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
</template>
9494

9595
<script setup lang="ts">
96-
import { until, useEventListener, whenever } from '@vueuse/core'
96+
import { until, useEventListener } from '@vueuse/core'
9797
import {
9898
computed,
9999
nextTick,
@@ -404,14 +404,34 @@ useNodeBadge()
404404
useGlobalLitegraph()
405405
useContextMenuTranslation()
406406
useVueFeatureFlags()
407+
useCopy()
408+
usePaste()
409+
useWorkflowAutoSave()
407410
408-
onMounted(async () => {
409-
useCopy()
410-
usePaste()
411-
useWorkflowAutoSave()
411+
// Start watching for locale change after the initial value is loaded.
412+
watch(
413+
() => settingStore.get('Comfy.Locale'),
414+
async (_newLocale, oldLocale) => {
415+
if (!oldLocale) return
416+
await until(() => isSettingsReady.value || !!settingsError.value).toBe(true)
417+
await Promise.all([
418+
until(() => isI18nReady.value || !!i18nError.value).toBe(true),
419+
newUserService().initializeIfNewUser(settingStore)
420+
])
421+
await useCommandStore().execute('Comfy.RefreshNodeDefinitions')
422+
await useWorkflowService().reloadCurrentWorkflow()
423+
}
424+
)
425+
useEventListener(
426+
() => useCanvasStore().canvas?.canvas,
427+
'litegraph:set-graph',
428+
() => {
429+
useWorkflowStore().updateActiveGraph()
430+
}
431+
)
412432
433+
onMounted(async () => {
413434
comfyApp.vueAppReady = true
414-
415435
workspaceStore.spinner = true
416436
// ChangeTracker needs to be initialized before setup, as it will overwrite
417437
// some listeners of litegraph canvas.
@@ -498,25 +518,6 @@ onMounted(async () => {
498518
const releaseStore = useReleaseStore()
499519
void releaseStore.initialize()
500520
501-
// Start watching for locale change after the initial value is loaded.
502-
watch(
503-
() => settingStore.get('Comfy.Locale'),
504-
async () => {
505-
await useCommandStore().execute('Comfy.RefreshNodeDefinitions')
506-
await useWorkflowService().reloadCurrentWorkflow()
507-
}
508-
)
509-
510-
whenever(
511-
() => useCanvasStore().canvas,
512-
(canvas) => {
513-
useEventListener(canvas.canvas, 'litegraph:set-graph', () => {
514-
useWorkflowStore().updateActiveGraph()
515-
})
516-
},
517-
{ immediate: true }
518-
)
519-
520521
emit('ready')
521522
})
522523

0 commit comments

Comments
 (0)