-
Notifications
You must be signed in to change notification settings - Fork 673
fix: make ComfyApp root-graph readiness reactive #14976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattmillerai
wants to merge
8
commits into
main
Choose a base branch
from
matt/fe-6860-root-graph-shallow-ref
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ef0059
fix: make ComfyApp root-graph readiness reactive
mattmillerai 37abbf4
test: cover rootGraph listener rebinding on graph replacement
mattmillerai d94c094
test: drop unused Pinia setup from rootGraphReadiness test
mattmillerai 9d36354
style: merge duplicate vue import in app.ts
mattmillerai 6c93b30
Merge remote-tracking branch 'origin/main' into matt/fe-6860-root-gra…
mattmillerai cf43654
Merge remote-tracking branch 'origin/main' into matt/fe-6860-root-gra…
mattmillerai 8cd9e62
Merge remote-tracking branch 'origin/main' into matt/fe-6860-root-gra…
mattmillerai 909788e
test: drop the type assertions from the root-graph test seam
mattmillerai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<LGraph | undefined> } | ||
|
|
||
| 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 | ||
| } | ||
|
mattmillerai marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<typeof effectScope> | ||
| 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() | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this without the type assertions by chance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes — dropped both assertions in
909788e0.TypeScript sanctions element access as the escape hatch for a
privatemember, soapp['rootGraphRef']reaches the same storage with no cast and no hand-written shadow interface. The seam is now two lines:The old
as unknown as AppWithRootGraphRefwas the worse form of the two problems: it did not just bypass privacy, it re-declared the field's type by hand, so a change torootGraphRefinapp.tswould have gone unnoticed here. Element access keeps the realShallowRef<LGraph | undefined>.Verified the type actually survives rather than degrading to
any— assigned anumberto.valueandpnpm typecheckrejected it (Type 'number' is not assignable to type 'LGraph'), then reverted.pnpm typecheck,pnpm lint,pnpm knip,pnpm formatall clean;rootGraphReadinessand bothcustomWidgetssuites green.