Skip to content

Commit d8887a4

Browse files
authored
Add Comfy.Workflow.SortNodeIdOnSave setting (#502)
* Update litegraph (Sort order) * nit * Add sort node on save setting * nit
1 parent 9d3ca76 commit d8887a4

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"dependencies": {
5858
"@atlaskit/pragmatic-drag-and-drop": "^1.2.1",
59-
"@comfyorg/litegraph": "^0.7.46",
59+
"@comfyorg/litegraph": "^0.7.47",
6060
"@primevue/themes": "^4.0.0-rc.2",
6161
"@vitejs/plugin-vue": "^5.0.5",
6262
"@vueuse/core": "^11.0.0",

src/scripts/app.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,10 @@ export class ComfyApp {
19251925

19261926
// Save current workflow automatically
19271927
setInterval(() => {
1928-
const workflow = JSON.stringify(this.graph.serialize())
1928+
const sortNodes =
1929+
this.vueAppReady &&
1930+
useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
1931+
const workflow = JSON.stringify(this.graph.serialize({ sortNodes }))
19291932
localStorage.setItem('workflow', workflow)
19301933
if (api.clientId) {
19311934
sessionStorage.setItem(`workflow:${api.clientId}`, workflow)
@@ -2396,7 +2399,10 @@ export class ComfyApp {
23962399
}
23972400
}
23982401

2399-
const workflow = graph.serialize()
2402+
const sortNodes =
2403+
this.vueAppReady &&
2404+
useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave')
2405+
const workflow = graph.serialize({ sortNodes })
24002406
const output = {}
24012407
// Process nodes in order of execution
24022408
for (const outerNode of graph.computeExecutionOrder(false)) {

src/stores/settingStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ export const useSettingStore = defineStore('setting', {
117117
max: 24
118118
}
119119
})
120+
121+
app.ui.settings.addSetting({
122+
id: 'Comfy.Workflow.SortNodeIdOnSave',
123+
name: 'Sort node IDs on save',
124+
type: 'boolean',
125+
defaultValue: false
126+
})
120127
},
121128

122129
set<K extends keyof Settings>(key: K, value: Settings[K]) {

src/types/apiTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ const zSettings = z.record(z.any()).and(
426426
'Comfy.SnapToGrid.GridSize': z.number(),
427427
'Comfy.TextareaWidget.FontSize': z.number(),
428428
'Comfy.UseNewMenu': z.any(),
429-
'Comfy.Validation.Workflows': z.boolean()
429+
'Comfy.Validation.Workflows': z.boolean(),
430+
'Comfy.Workflow.SortNodeIdOnSave': z.boolean()
430431
})
431432
.optional()
432433
)

tests-ui/tests/litegraph.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ describe('LGraph', () => {
2929
const node2 = new DummyNode()
3030
const graph = createGraph(node1, node2)
3131

32-
const result1 = graph.serialize()
32+
const result1 = graph.serialize({ sortNodes: true })
3333
expect(result1.nodes).not.toHaveLength(0)
34-
// @ts-expect-error
34+
// @ts-expect-error Access private property.
3535
graph._nodes = swapNodes(graph._nodes)
36-
const result2 = graph.serialize()
36+
const result2 = graph.serialize({ sortNodes: true })
3737

3838
expect(result1).toEqual(result2)
3939
})

0 commit comments

Comments
 (0)