From 7ef00598d0ebe4c7aaea999ac8fdc32f0e90f722 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 9 Aug 2026 12:08:11 -0700 Subject: [PATCH 1/8] fix: make ComfyApp root-graph readiness reactive Back the root graph with a shallowRef so watchers, computeds and useEventListener sources that read app.graph / app.rootGraph / app.isGraphReady re-evaluate when setup() assigns the graph. Stores constructed before ComfyApp.setup() runs (FirstRunTour pulls in appModeStore on every cold start) previously bound to a plain field with no reactive dependency, so a listener registered against app.rootGraph?.events never rebound once the graph existed. --- .../core/customWidgets.clone.test.ts | 9 ++- .../customWidgets.subgraphPromotion.test.ts | 17 +++--- src/scripts/__tests__/appTestUtils.ts | 22 ++++++++ src/scripts/app.test.ts | 50 +++++++++-------- src/scripts/app.ts | 13 +++-- src/scripts/rootGraphReadiness.test.ts | 55 +++++++++++++++++++ 6 files changed, 121 insertions(+), 45 deletions(-) create mode 100644 src/scripts/__tests__/appTestUtils.ts create mode 100644 src/scripts/rootGraphReadiness.test.ts diff --git a/src/extensions/core/customWidgets.clone.test.ts b/src/extensions/core/customWidgets.clone.test.ts index 681c8db4186..4f883380a78 100644 --- a/src/extensions/core/customWidgets.clone.test.ts +++ b/src/extensions/core/customWidgets.clone.test.ts @@ -5,6 +5,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' import { app } from '@/scripts/app' +import { getRootGraph, setRootGraph } from '@/scripts/__tests__/appTestUtils' import { useExtensionStore } from '@/stores/extensionStore' import type { ComfyExtension } from '@/types/comfy' @@ -65,10 +66,8 @@ describe('CustomCombo copy/paste', () => { it('preserves combo options and selected value through clone and paste', () => { const graph = new LGraph() - type AppWithRootGraph = { rootGraphInternal?: LGraph } - const appWithRootGraph = app as unknown as AppWithRootGraph - const previousRootGraph = appWithRootGraph.rootGraphInternal - appWithRootGraph.rootGraphInternal = graph + const previousRootGraph = getRootGraph(app) + setRootGraph(app, graph) try { const original = LiteGraph.createNode(TEST_CUSTOM_COMBO_TYPE)! @@ -97,7 +96,7 @@ describe('CustomCombo copy/paste', () => { 'gamma' ]) } finally { - appWithRootGraph.rootGraphInternal = previousRootGraph + setRootGraph(app, previousRootGraph) } }) }) diff --git a/src/extensions/core/customWidgets.subgraphPromotion.test.ts b/src/extensions/core/customWidgets.subgraphPromotion.test.ts index f63c5167d08..49fe70fcfb6 100644 --- a/src/extensions/core/customWidgets.subgraphPromotion.test.ts +++ b/src/extensions/core/customWidgets.subgraphPromotion.test.ts @@ -11,6 +11,7 @@ import { } from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' import { app } from '@/scripts/app' +import { getRootGraph, setRootGraph } from '@/scripts/__tests__/appTestUtils' import { useExtensionStore } from '@/stores/extensionStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import type { ComfyExtension } from '@/types/comfy' @@ -122,10 +123,8 @@ describe('CustomCombo index widget after subgraph promotion', () => { it('resolves INDEX from the promoted host choice, not the frozen interior value', async () => { const rootGraph = new LGraph() - type AppWithRootGraph = { rootGraphInternal?: LGraph } - const appWithRootGraph = app as unknown as AppWithRootGraph - const previousRootGraph = appWithRootGraph.rootGraphInternal - appWithRootGraph.rootGraphInternal = rootGraph + const previousRootGraph = getRootGraph(app) + setRootGraph(app, rootGraph) try { const subgraph = createTestSubgraph({ rootGraph }) @@ -167,16 +166,14 @@ describe('CustomCombo index widget after subgraph promotion', () => { // "four" is index 3 of ["one", "two", "three", "four"]. expect(promptInputs.index).toBe(3) } finally { - appWithRootGraph.rootGraphInternal = previousRootGraph + setRootGraph(app, previousRootGraph) } }) it('resolves INDEX from the interior widget when choice was never promoted', async () => { const rootGraph = new LGraph() - type AppWithRootGraph = { rootGraphInternal?: LGraph } - const appWithRootGraph = app as unknown as AppWithRootGraph - const previousRootGraph = appWithRootGraph.rootGraphInternal - appWithRootGraph.rootGraphInternal = rootGraph + const previousRootGraph = getRootGraph(app) + setRootGraph(app, rootGraph) try { const comboNode = LiteGraph.createNode( @@ -195,7 +192,7 @@ describe('CustomCombo index widget after subgraph promotion', () => { // "two" is index 1 of ["one", "two", "three"]. expect(promptInputs.index).toBe(1) } finally { - appWithRootGraph.rootGraphInternal = previousRootGraph + setRootGraph(app, previousRootGraph) } }) }) diff --git a/src/scripts/__tests__/appTestUtils.ts b/src/scripts/__tests__/appTestUtils.ts new file mode 100644 index 00000000000..6d89ad4861d --- /dev/null +++ b/src/scripts/__tests__/appTestUtils.ts @@ -0,0 +1,22 @@ +import type { ShallowRef } from 'vue' + +import type { LGraph } from '@/lib/litegraph/src/litegraph' +import type { ComfyApp } from '@/scripts/app' + +/** + * `ComfyApp.setup` is the only production writer of the root graph, and it needs + * a real canvas. Tests that just need a graph in place reach the same storage + * through this seam instead. + */ +type AppWithRootGraphRef = { rootGraphRef: ShallowRef } + +const rootGraphRefOf = (app: ComfyApp) => + (app as unknown as AppWithRootGraphRef).rootGraphRef + +export function setRootGraph(app: ComfyApp, graph: LGraph | undefined) { + rootGraphRefOf(app).value = graph +} + +export function getRootGraph(app: ComfyApp) { + return rootGraphRefOf(app).value +} diff --git a/src/scripts/app.test.ts b/src/scripts/app.test.ts index 134c28fec6e..8b86f910777 100644 --- a/src/scripts/app.test.ts +++ b/src/scripts/app.test.ts @@ -1,4 +1,5 @@ import { createTestingPinia } from '@pinia/testing' +import { fromPartial } from '@total-typescript/shoehorn' import { setActivePinia } from 'pinia' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -18,6 +19,7 @@ import { createMockChangeTracker } from '@/utils/__tests__/litegraphTestUtils' import { useNodeReplacementStore } from '@/platform/nodeReplacement/nodeReplacementStore' import type { NodeReplacement } from '@/platform/nodeReplacement/types' import { ComfyApp, app as singletonApp } from './app' +import { setRootGraph } from './__tests__/appTestUtils' import { createNode } from '@/utils/litegraphUtil' import { pasteAudioNode, @@ -302,8 +304,8 @@ describe('ComfyApp', () => { size: 0 }) const graph = new LGraph() - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) mockWorkspaceWorkflow.activeWorkflow = workflow vi.spyOn(app, 'graphToPrompt').mockResolvedValue({ output: {}, @@ -340,8 +342,8 @@ describe('ComfyApp', () => { ] } } - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) mockWorkspaceWorkflow.activeWorkflow = workflow vi.spyOn(app, 'graphToPrompt').mockResolvedValue({ output: promptOutput, @@ -792,8 +794,8 @@ describe('ComfyApp', () => { it('clears missing node packs before loading API JSON without missing nodes', async () => { const graph = new LGraph() const activeSubgraph = createTestSubgraph({ rootGraph: graph }) - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) Reflect.set(mockCanvas, 'graph', activeSubgraph) Reflect.set(mockCanvas, 'subgraph', activeSubgraph) vi.mocked(mockCanvas.setGraph).mockImplementation((nextGraph) => { @@ -829,8 +831,8 @@ describe('ComfyApp', () => { it('creates a removable placeholder for an API JSON missing node', async () => { const graph = new LGraph() - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) const cleanupErrorHooks = installErrorClearingHooks(graph) const missingNodesStore = useMissingNodesErrorStore() const missingNodeType = 'Uninstalled<&Node>' @@ -895,8 +897,8 @@ describe('ComfyApp', () => { it('preserves API JSON inputs on a missing node across reload', async () => { const graph = new LGraph() - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) const sourceNodeType = 'test/ApiJsonSourceNode' const missingNodeType = 'UninstalledInputNode' class ApiJsonSourceNode extends LGraphNode { @@ -1000,8 +1002,8 @@ describe('ComfyApp', () => { it('defers API JSON missing node warnings until they are flushed', async () => { const graph = new LGraph() - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) const nodeReplacementStore = useNodeReplacementStore() vi.spyOn(nodeReplacementStore, 'load').mockResolvedValue() vi.spyOn(nodeReplacementStore, 'getReplacementFor').mockReturnValue(null) @@ -1129,7 +1131,7 @@ describe('ComfyApp', () => { experimental: false } } - Reflect.set(app, 'rootGraphInternal', rootGraph) + setRootGraph(app, rootGraph) vi.spyOn(app, 'getNodeDefs').mockResolvedValue(defs) vi.spyOn(app, 'registerNodeDef').mockResolvedValue(undefined) @@ -1148,15 +1150,15 @@ describe('ComfyApp', () => { describe('refreshMissingModels', () => { it('delegates to the app-independent missing model refresh pipeline', async () => { - const graph = { + const graph = fromPartial({ nodes: [], serialize: vi.fn(() => createWorkflowGraphData()) - } + }) const result = { missingModels: [], confirmedCandidates: [] } - Reflect.set(app, 'rootGraphInternal', graph) + setRootGraph(app, graph) vi.spyOn(app, 'reloadNodeDefs').mockResolvedValue() mockRefreshMissingModelPipeline.mockResolvedValue(result) @@ -1176,11 +1178,11 @@ describe('ComfyApp', () => { }) it('omits the node definition reload when reloadDefs is false', async () => { - const graph = { + const graph = fromPartial({ nodes: [], serialize: vi.fn(() => createWorkflowGraphData()) - } - Reflect.set(app, 'rootGraphInternal', graph) + }) + setRootGraph(app, graph) vi.spyOn(app, 'reloadNodeDefs').mockResolvedValue() mockRefreshMissingModelPipeline.mockResolvedValue({ missingModels: [], @@ -1565,7 +1567,7 @@ describe('ComfyApp', () => { it('preserves the current graph when A1111 core nodes are unavailable', async () => { const graph = new LGraph() const parameters = 'positive\nNegative prompt: negative\nSteps: 20' - Reflect.set(app, 'rootGraphInternal', graph) + setRootGraph(app, graph) vi.mocked(getWorkflowDataFromFile).mockResolvedValue({ parameters }) mockImportA1111.mockResolvedValue('core-nodes-unavailable') @@ -1588,7 +1590,7 @@ describe('ComfyApp', () => { it('shows one file-load error when parameters are not A1111-shaped', async () => { const graph = new LGraph() const parameters = 'positive\nSteps: 20' - Reflect.set(app, 'rootGraphInternal', graph) + setRootGraph(app, graph) vi.mocked(getWorkflowDataFromFile).mockResolvedValue({ parameters }) mockImportA1111.mockResolvedValue('not-a1111') @@ -1605,7 +1607,7 @@ describe('ComfyApp', () => { it('awaits persistence and orders its clear callback before setGraph', async () => { const graph = new LGraph() const parameters = 'positive\nNegative prompt: negative\nSteps: 20' - Reflect.set(app, 'rootGraphInternal', graph) + setRootGraph(app, graph) vi.mocked(getWorkflowDataFromFile).mockResolvedValue({ parameters }) mockImportA1111.mockImplementation( async (_graph, _parameters, beforeGraphClear) => { @@ -1656,8 +1658,8 @@ describe('ComfyApp', () => { } as unknown as LGraphCanvas const graph = new LGraph() - Reflect.set(app, 'rootGraphInternal', graph) - Reflect.set(singletonApp, 'rootGraphInternal', graph) + setRootGraph(app, graph) + setRootGraph(singletonApp, graph) const outgoingWorkflow = new ComfyWorkflow({ path: 'workflows/outgoing.json', modified: 0, diff --git a/src/scripts/app.ts b/src/scripts/app.ts index c71c185db83..6920e23f595 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -281,24 +281,25 @@ export class ComfyApp { private _nodeOutputs!: Record nodePreviewImages: Record - private rootGraphInternal: LGraph | undefined + /** Shallow: the graph is observed for readiness, never deep-proxied. */ + private readonly rootGraphRef = shallowRef(undefined) // TODO: Migrate internal usage to the /** @deprecated Use {@link rootGraph} instead */ get graph() { - return this.rootGraphInternal! + return this.rootGraphRef.value! } get rootGraph(): LGraph { - if (!this.rootGraphInternal) { + if (!this.rootGraphRef.value) { console.error('ComfyApp graph accessed before initialization') } - return this.rootGraphInternal! + return this.rootGraphRef.value! } /** Whether the root graph has been initialized. Safe to check without triggering error logs. */ get isGraphReady(): boolean { - return !!this.rootGraphInternal + return !!this.rootGraphRef.value } canvas!: LGraphCanvas @@ -957,7 +958,7 @@ export class ComfyApp { this.addAfterConfigureHandler(graph) - this.rootGraphInternal = graph + this.rootGraphRef.value = graph installNodeAddedTelemetry(graph) this.canvas = new LGraphCanvas(canvasEl, graph) // Make canvas states reactive so we can observe changes on them. diff --git a/src/scripts/rootGraphReadiness.test.ts b/src/scripts/rootGraphReadiness.test.ts new file mode 100644 index 00000000000..2fa489543a1 --- /dev/null +++ b/src/scripts/rootGraphReadiness.test.ts @@ -0,0 +1,55 @@ +import { useEventListener } from '@vueuse/core' +import { createPinia, setActivePinia } from 'pinia' +import { effectScope, nextTick, watchEffect } from 'vue' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { LGraph } from '@/lib/litegraph/src/litegraph' +import { getRootGraph, setRootGraph } from '@/scripts/__tests__/appTestUtils' +import { app } from '@/scripts/app' + +describe('ComfyApp root graph readiness', () => { + let scope: ReturnType + let previousRootGraph: LGraph | undefined + + beforeEach(() => { + setActivePinia(createPinia()) + vi.spyOn(console, 'error').mockImplementation(() => {}) + previousRootGraph = getRootGraph(app) + setRootGraph(app, undefined) + scope = effectScope() + }) + + afterEach(() => { + scope.stop() + setRootGraph(app, previousRootGraph) + vi.restoreAllMocks() + }) + + it('re-runs an effect reading isGraphReady when the graph is assigned', async () => { + const readiness: boolean[] = [] + scope.run(() => { + watchEffect(() => readiness.push(app.isGraphReady)) + }) + + expect(readiness).toEqual([false]) + + setRootGraph(app, new LGraph()) + await nextTick() + + expect(readiness).toEqual([false, true]) + }) + + it('binds a rootGraph.events listener registered before the graph exists', async () => { + const onConfigured = vi.fn() + scope.run(() => { + useEventListener(() => app.rootGraph?.events, 'configured', onConfigured) + }) + + const graph = new LGraph() + setRootGraph(app, graph) + await nextTick() + graph.events.dispatch('configured') + + expect(onConfigured).toHaveBeenCalledOnce() + }) +}) From 37abbf4b9d1536dd5b2dc581210bad824e631d39 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 9 Aug 2026 12:27:40 -0700 Subject: [PATCH 2/8] test: cover rootGraph listener rebinding on graph replacement --- src/scripts/rootGraphReadiness.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/scripts/rootGraphReadiness.test.ts b/src/scripts/rootGraphReadiness.test.ts index 2fa489543a1..6b8c1fdb19b 100644 --- a/src/scripts/rootGraphReadiness.test.ts +++ b/src/scripts/rootGraphReadiness.test.ts @@ -52,4 +52,23 @@ describe('ComfyApp root graph readiness', () => { expect(onConfigured).toHaveBeenCalledOnce() }) + + it('rebinds a rootGraph.events listener when the graph is replaced', async () => { + const onConfigured = vi.fn() + const firstGraph = new LGraph() + setRootGraph(app, firstGraph) + scope.run(() => { + useEventListener(() => app.rootGraph?.events, 'configured', onConfigured) + }) + + const secondGraph = new LGraph() + setRootGraph(app, secondGraph) + await nextTick() + + firstGraph.events.dispatch('configured') + expect(onConfigured).not.toHaveBeenCalled() + + secondGraph.events.dispatch('configured') + expect(onConfigured).toHaveBeenCalledOnce() + }) }) From d94c094d8a03989f56097a1b8212631a39eb041c Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 9 Aug 2026 22:00:34 -0700 Subject: [PATCH 3/8] test: drop unused Pinia setup from rootGraphReadiness test The suite never reaches a store, so the global Pinia instance was dead setup. Verified the three cases still pass without it. --- src/scripts/rootGraphReadiness.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/scripts/rootGraphReadiness.test.ts b/src/scripts/rootGraphReadiness.test.ts index 6b8c1fdb19b..94ca9598189 100644 --- a/src/scripts/rootGraphReadiness.test.ts +++ b/src/scripts/rootGraphReadiness.test.ts @@ -1,5 +1,4 @@ import { useEventListener } from '@vueuse/core' -import { createPinia, setActivePinia } from 'pinia' import { effectScope, nextTick, watchEffect } from 'vue' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -12,7 +11,6 @@ describe('ComfyApp root graph readiness', () => { let previousRootGraph: LGraph | undefined beforeEach(() => { - setActivePinia(createPinia()) vi.spyOn(console, 'error').mockImplementation(() => {}) previousRootGraph = getRootGraph(app) setRootGraph(app, undefined) From d5cb5715e880896abc248ba20e713f441faeb70f Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 9 Aug 2026 23:09:47 -0700 Subject: [PATCH 4/8] style: merge duplicate vue import in app.ts Adding shallowRef left app.ts as the only file in the repo with two value imports from 'vue'. --- src/scripts/app.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 6920e23f595..a0446eddb4e 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1,8 +1,7 @@ import { useEventListener, useResizeObserver } from '@vueuse/core' import _ from 'es-toolkit/compat' import type { ToastMessageOptions } from 'primevue/toast' -import { reactive, unref } from 'vue' -import { shallowRef } from 'vue' +import { reactive, shallowRef, unref } from 'vue' import { useCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion' import { layoutStore } from '@/renderer/core/layout/store/layoutStore' From 967997deba64fc424c8981404270e890404002af Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sat, 15 Aug 2026 23:35:19 -0700 Subject: [PATCH 5/8] test: drop the type assertions from the root-graph test seam Element access reaches a TypeScript `private` member without an assertion, so the seam keeps the real `ShallowRef` type instead of laundering it through a hand-written shadow interface. --- src/scripts/__tests__/appTestUtils.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/scripts/__tests__/appTestUtils.ts b/src/scripts/__tests__/appTestUtils.ts index 6d89ad4861d..a1516a104d9 100644 --- a/src/scripts/__tests__/appTestUtils.ts +++ b/src/scripts/__tests__/appTestUtils.ts @@ -1,5 +1,3 @@ -import type { ShallowRef } from 'vue' - import type { LGraph } from '@/lib/litegraph/src/litegraph' import type { ComfyApp } from '@/scripts/app' @@ -8,15 +6,10 @@ import type { ComfyApp } from '@/scripts/app' * a real canvas. Tests that just need a graph in place reach the same storage * through this seam instead. */ -type AppWithRootGraphRef = { rootGraphRef: ShallowRef } - -const rootGraphRefOf = (app: ComfyApp) => - (app as unknown as AppWithRootGraphRef).rootGraphRef - export function setRootGraph(app: ComfyApp, graph: LGraph | undefined) { - rootGraphRefOf(app).value = graph + app['rootGraphRef'].value = graph } export function getRootGraph(app: ComfyApp) { - return rootGraphRefOf(app).value + return app['rootGraphRef'].value } From 3a0983f37742fb41daa9ade62062d7046092966c Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Tue, 25 Aug 2026 05:46:46 -0700 Subject: [PATCH 6/8] test: drop redundant vi.restoreAllMocks from rootGraphReadiness afterEach The oxlint no-redundant-vitest-cleanup rule (added on main) flags this as already handled by the project's global test setup. --- src/scripts/rootGraphReadiness.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/rootGraphReadiness.test.ts b/src/scripts/rootGraphReadiness.test.ts index 94ca9598189..f701a6d38d2 100644 --- a/src/scripts/rootGraphReadiness.test.ts +++ b/src/scripts/rootGraphReadiness.test.ts @@ -20,7 +20,6 @@ describe('ComfyApp root graph readiness', () => { afterEach(() => { scope.stop() setRootGraph(app, previousRootGraph) - vi.restoreAllMocks() }) it('re-runs an effect reading isGraphReady when the graph is assigned', async () => { From 2f9ce28b50b6ac8a0dae4c51bbeecad6ecc46d9f Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Fri, 9 Oct 2026 12:13:35 +0000 Subject: [PATCH 7/8] test: use rootGraphOrUndefined and drop redundant console.error spy --- src/scripts/rootGraphReadiness.test.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/scripts/rootGraphReadiness.test.ts b/src/scripts/rootGraphReadiness.test.ts index f701a6d38d2..299651cb4d8 100644 --- a/src/scripts/rootGraphReadiness.test.ts +++ b/src/scripts/rootGraphReadiness.test.ts @@ -11,7 +11,6 @@ describe('ComfyApp root graph readiness', () => { let previousRootGraph: LGraph | undefined beforeEach(() => { - vi.spyOn(console, 'error').mockImplementation(() => {}) previousRootGraph = getRootGraph(app) setRootGraph(app, undefined) scope = effectScope() @@ -39,7 +38,11 @@ describe('ComfyApp root graph readiness', () => { it('binds a rootGraph.events listener registered before the graph exists', async () => { const onConfigured = vi.fn() scope.run(() => { - useEventListener(() => app.rootGraph?.events, 'configured', onConfigured) + useEventListener( + () => app.rootGraphOrUndefined?.events, + 'configured', + onConfigured + ) }) const graph = new LGraph() @@ -55,7 +58,11 @@ describe('ComfyApp root graph readiness', () => { const firstGraph = new LGraph() setRootGraph(app, firstGraph) scope.run(() => { - useEventListener(() => app.rootGraph?.events, 'configured', onConfigured) + useEventListener( + () => app.rootGraphOrUndefined?.events, + 'configured', + onConfigured + ) }) const secondGraph = new LGraph() From e2c2d4ee02f8e4c3f31f97c4d45b9955bd3f6e27 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Fri, 9 Oct 2026 12:32:24 +0000 Subject: [PATCH 8/8] fix: seed matrix runner root graph through rootGraphRef The ecosystem matrix runner still wrote the removed rootGraphInternal field, leaving app.rootGraph undefined and silencing the detection proof. --- scripts/registry-census/matrix_runner.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/registry-census/matrix_runner.ts b/scripts/registry-census/matrix_runner.ts index 7157d8e2c3d..8518c27dd2f 100644 --- a/scripts/registry-census/matrix_runner.ts +++ b/scripts/registry-census/matrix_runner.ts @@ -19,6 +19,7 @@ import type { import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import type { ComfyNodeDef, InputSpec } from '@/schemas/nodeDefSchema' +import { setRootGraph } from '@/scripts/__tests__/appTestUtils' import type { useWidgetValueStore } from '@/stores/widgetValueStore' const S = (v: unknown) => JSON.stringify(v) @@ -325,8 +326,8 @@ export async function runPack( const graph = new LGraph() // ComfyApp.setup() non-null-asserts five DOM elements and needs a 2D // context, so it cannot boot here. DOM widgets read app.rootGraph while - // graph.configure runs, so the private field has to be seeded directly. - Reflect.set(app, 'rootGraphInternal', graph) + // graph.configure runs, so the root graph has to be seeded directly. + setRootGraph(app, graph) const byType = (t: string) => graph._nodes.find((n) => n.type === t) let wvStore: WidgetValueStore | undefined