Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
99148a3
fix(litegraph): recover graph ID allocation safely
christian-byrne Sep 28, 2026
ddaf62c
fix(litegraph): address safe ID review findings
christian-byrne Sep 28, 2026
d45096c
fix(litegraph): close safe ID current-head review
christian-byrne Sep 28, 2026
d45e6f8
test(litegraph): expect wrapped link counter advancement
christian-byrne Sep 28, 2026
76e842e
fix(group-node): validate primitive link slot types
christian-byrne Sep 28, 2026
1a5b87f
perf(litegraph): avoid collecting node IDs on sequential mint
christian-byrne Sep 28, 2026
9024772
fix(litegraph): force removal during paste rollback
christian-byrne Sep 28, 2026
65b8b61
test(group-node): use supported parameterized API
christian-byrne Sep 28, 2026
3503b1f
test(litegraph): cover indexed ID collision fallback
christian-byrne Sep 28, 2026
7daf736
fix(litegraph): make paste creation rollback-safe
christian-byrne Sep 28, 2026
723150b
test(litegraph): align failed configure rollback pins
christian-byrne Sep 28, 2026
36d3dab
fix(litegraph): complete safe ID recovery follow-up
ampagent Sep 28, 2026
b59e0c2
fix(litegraph): keep ID recovery non-throwing
ampagent Sep 28, 2026
a7eec1e
fix(litegraph): refresh safe ID recovery onto graph API
christian-byrne Sep 29, 2026
cb62565
chore: merge current main into safe ID refresh
christian-byrne Sep 29, 2026
54d94af
fix: address safe ID review and cloud teardown
christian-byrne Sep 30, 2026
7f790eb
fix(litegraph): refresh safe ID recovery on current main
christian-byrne Sep 30, 2026
949645e
fix(litegraph): retain falsy paste finalization errors
christian-byrne Sep 30, 2026
281b360
fix(litegraph): retain falsy paste operation errors
christian-byrne Sep 30, 2026
9fa92cf
chore: merge current main into safe ID recovery
christian-byrne Oct 1, 2026
a2a7669
test(litegraph): pin safe ID recovery against production reserved-ran…
christian-byrne Oct 1, 2026
39d8e61
test(litegraph): tighten safe ID recovery proof
christian-byrne Oct 1, 2026
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "9a37f747-e96b-4304-9212-7abcaad7bdac",
"revision": 0,
"last_node_id": 5,
"last_link_id": 5,
"last_node_id": 4462758126524329,
"last_link_id": 7729209487955825,
"nodes": [
{
"id": 5,
Expand Down
8 changes: 5 additions & 3 deletions browser_tests/fixtures/webSessionFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ export const webSessionTest = comfyPageFixture.extend<WebSessionFixtures>({

await context.addCookies([{ ...WEB_SESSION_COOKIE, url: APP_URL }])

await use(page)

await page.unrouteAll({ behavior: 'ignoreErrors' })
try {
await use(page)
} finally {
await page.unrouteAll({ behavior: 'ignoreErrors' })
}
}
})
40 changes: 40 additions & 0 deletions browser_tests/tests/copyPaste.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,46 @@ test.describe('Copy Paste', { tag: ['@screenshot', '@workflow'] }, () => {
})
})

test('Sparse clipboard widget values keep their original indices', async ({
comfyPage
}) => {
const originalNodes = await comfyPage.nodeOps.getNodeRefsByType('KSampler')
const originalIds = new Set(originalNodes.map(({ id }) => id))

await comfyPage.page.evaluate(() => {
const node = window
.app!.graph.serialize()
.nodes.find(({ type }) => type === 'KSampler')
if (!node) throw new Error('KSampler node not found')
const clipboardNode = {
...node,
widgets_values: { 0: 123, 2: 47, length: 3 }
}
const encoded = btoa(JSON.stringify({ nodes: [clipboardNode] }))
const dataTransfer = new DataTransfer()
dataTransfer.setData(
'text/html',
`<meta charset="utf-8"><div><span data-comfy-metadata="${encoded}"></span></div><span style="white-space:pre-wrap;">Text</span>`
)
document.dispatchEvent(
new ClipboardEvent('paste', {
clipboardData: dataTransfer,
bubbles: true,
cancelable: true
})
)
})

await expect
.poll(async () => {
const nodes = await comfyPage.nodeOps.getNodeRefsByType('KSampler')
const pasted = nodes.find(({ id }) => !originalIds.has(id))
if (!pasted) return undefined
return await (await pasted.getWidget(2)).getValue()
})
.toBe(47)
})

test('Can undo paste multiple nodes as single action', async ({
comfyPage
}) => {
Expand Down
5 changes: 0 additions & 5 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@
"count": 1
}
},
"src/lib/litegraph/src/subgraph/subgraphDeduplication.ts": {
"comfy/no-new-error-throw": {
"count": 1
}
},
"src/platform/assets/services/assetService.ts": {
"comfy/no-new-error-throw": {
"count": 21
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useCopy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function selectDocumentText(selectedCharacters: number): void {
function readSerializedClipboardMetadata(dataTransfer: DataTransfer): string {
const match = dataTransfer
.getData('text/html')
.match(/data-metadata="([A-Za-z0-9+/=]+)"/)?.[1]
.match(/data-comfy-metadata="([A-Za-z0-9+/=]+)"/)?.[1]
expect(match).toBeDefined()
if (!match) throw new Error('Expected clipboard metadata to be written')

Expand Down
2 changes: 1 addition & 1 deletion src/composables/useCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const CANVAS_CLIPBOARD_KEY = 'litegrapheditor_clipboard'
const CANVAS_CLIPBOARD_ID_KEY = 'litegrapheditor_clipboard_id'

const clipboardHTMLWrapper = [
'<meta charset="utf-8"><div><span data-metadata="',
'<meta charset="utf-8"><div><span data-comfy-metadata="',
'"></span></div><span style="white-space:pre-wrap;">Text</span>'
]
const clipboardByteChunkSize = 0x8000
Expand Down
144 changes: 139 additions & 5 deletions src/composables/usePaste.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
LGraphNode
} from '@/lib/litegraph/src/litegraph'
import { app } from '@/scripts/app'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { createMockLGraphNode } from '@/utils/__tests__/litegraphTestUtils'
import { createNode } from '@/utils/litegraphUtil'
import { shouldIgnoreCopyPaste } from '@/workbench/eventHelpers'
Expand Down Expand Up @@ -79,6 +80,11 @@ function pastedClipboard(kind: 'workflow JSON' | 'an image'): DataTransfer {
return dataTransfer
}

function clipboardHtml(data: unknown, attribute = 'data-comfy-metadata') {
const encoded = btoa(JSON.stringify(data))
return `<meta charset="utf-8"><div><span ${attribute}="${encoded}"></span></div><span style="white-space:pre-wrap;">Text</span>`
}

function mountRichTextEditor() {
const editor = document.createElement('div')
editor.contentEditable = 'true'
Expand Down Expand Up @@ -679,9 +685,14 @@ describe('usePaste', () => {
})

it('should handle clipboard items with metadata', async () => {
const data = { test: 'data' }
const encoded = btoa(JSON.stringify(data))
const html = `<div data-metadata="${encoded}"></div>`
const data = {
nodes: [],
groups: [],
reroutes: [],
links: [],
subgraphs: []
}
const html = clipboardHtml(data)

usePaste()

Expand All @@ -699,6 +710,130 @@ describe('usePaste', () => {
})
})

it('accepts validated legacy data-metadata clipboard items', async () => {
const data = { nodes: [] }
const html = clipboardHtml(data, 'data-metadata')

usePaste()

const dataTransfer = new DataTransfer()
dataTransfer.setData('text/html', html)
dataTransfer.setData('text/plain', 'some text')

const event = new ClipboardEvent('paste', { clipboardData: dataTransfer })
document.dispatchEvent(event)

await vi.waitFor(() => {
expect(mockCanvas._deserializeItems).toHaveBeenCalledWith(
data,
expect.any(Object)
)
})
})

it('does not treat metadata embedded in arbitrary HTML as a Comfy clipboard', async () => {
const encoded = btoa(JSON.stringify({ nodes: [] }))
const html = `<article><span data-comfy-metadata="${encoded}"></span></article>`

usePaste()
const dataTransfer = new DataTransfer()
dataTransfer.setData('text/html', html)
document.dispatchEvent(
new ClipboardEvent('paste', { clipboardData: dataTransfer })
)

await vi.waitFor(() => {
expect(mockCanvas._deserializeItems).not.toHaveBeenCalled()
expect(mockCanvas.pasteFromClipboard).toHaveBeenCalled()
})
})

it.for([
{ name: 'null payload', data: null },
{ name: 'empty object', data: {} },
{ name: 'malformed node', data: { nodes: [{ type: 'KSampler' }] } },
{ name: 'malformed group', data: { groups: [{ id: 1 }] } },
{ name: 'malformed reroute', data: { reroutes: [{ id: 1 }] } },
{ name: 'malformed link', data: { links: [{ id: 1 }] } },
{ name: 'malformed subgraph', data: { subgraphs: [{ id: 'invalid' }] } }
])(
'rejects malformed Comfy metadata without stale fallback: $name',
async ({ data }) => {
const html = clipboardHtml(data)

usePaste()

const dataTransfer = new DataTransfer()
dataTransfer.setData('text/html', html)
dataTransfer.setData('text/plain', 'some text')

document.dispatchEvent(
new ClipboardEvent('paste', { clipboardData: dataTransfer })
)

await vi.waitFor(() => {
expect(mockCanvas._deserializeItems).not.toHaveBeenCalled()
expect(mockCanvas.pasteFromClipboard).not.toHaveBeenCalled()
expect(useToastStore().add).toHaveBeenCalledWith(
expect.objectContaining({ severity: 'error' })
)
})
}
)

it('rejects invalid Comfy JSON without stale fallback', async () => {
const html = `<meta charset="utf-8"><div><span data-comfy-metadata="${btoa('{')}"></span></div><span style="white-space:pre-wrap;">Text</span>`

usePaste()

const dataTransfer = new DataTransfer()
dataTransfer.setData('text/html', html)
dataTransfer.setData('text/plain', 'some text')

document.dispatchEvent(
new ClipboardEvent('paste', { clipboardData: dataTransfer })
)

await vi.waitFor(() => {
expect(mockCanvas._deserializeItems).not.toHaveBeenCalled()
expect(mockCanvas.pasteFromClipboard).not.toHaveBeenCalled()
expect(useToastStore().add).toHaveBeenCalledWith(
expect.objectContaining({ severity: 'error' })
)
})
})

it('should toast a deserialization error without falling back', async () => {
const deserializeError = new Error('Paste failed')
vi.mocked(mockCanvas._deserializeItems).mockImplementation(() => {
throw deserializeError
})
const data = {
nodes: [],
groups: [],
reroutes: [],
links: [],
subgraphs: []
}
const html = clipboardHtml(data)

usePaste()

const dataTransfer = new DataTransfer()
dataTransfer.setData('text/html', html)
dataTransfer.setData('text/plain', 'some text')

const event = new ClipboardEvent('paste', { clipboardData: dataTransfer })
document.dispatchEvent(event)

await vi.waitFor(() => {
expect(useToastStore().add).toHaveBeenCalledWith(
expect.objectContaining({ severity: 'error' })
)
expect(mockCanvas.pasteFromClipboard).not.toHaveBeenCalled()
})
})

it('should skip node metadata paste when a media node is selected', async () => {
const mockNode = createMockLGraphNode({
is_selected: true,
Expand All @@ -711,8 +846,7 @@ describe('usePaste', () => {
usePaste()

const nodeData = { nodes: [{ type: 'KSampler' }] }
const encoded = btoa(JSON.stringify(nodeData))
const html = `<div data-metadata="${encoded}"></div>`
const html = clipboardHtml(nodeData)

const dataTransfer = new DataTransfer()
dataTransfer.setData('text/html', html)
Expand Down
27 changes: 22 additions & 5 deletions src/composables/usePaste.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useEventListener } from '@vueuse/core'

import { useErrorHandling } from '@/composables/useErrorHandling'
import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph'
import { zClipboardItems } from '@/platform/workflow/validation/schemas/workflowSchema'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { app } from '@/scripts/app'
import { useWorkspaceStore } from '@/stores/workspaceStore'
Expand Down Expand Up @@ -42,19 +44,34 @@ export function cloneDataTransfer(original: DataTransfer): DataTransfer {

function pasteClipboardItems(data: DataTransfer): boolean {
const rawData = data.getData('text/html')
const match = rawData.match(/data-metadata="([A-Za-z0-9+/=]+)"/)?.[1]
const match = rawData.match(
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
/^<meta charset="utf-8"><div><span data-(?:comfy-)?metadata="([A-Za-z0-9+/=]+)"><\/span><\/div><span style="white-space:pre-wrap;">Text<\/span>$/
)?.[1]
if (!match) return false

let parsed: unknown
try {
// Decode UTF-8 safe base64
const binaryString = atob(match)
const bytes = Uint8Array.from(binaryString, (c) => c.charCodeAt(0))
const decodedData = new TextDecoder().decode(bytes)
useCanvasStore().getCanvas()._deserializeItems(JSON.parse(decodedData), {})
parsed = JSON.parse(decodedData)
} catch (err) {
useErrorHandling().toastErrorHandler(err)
return true
}

const clipboardItems = zClipboardItems.safeParse(parsed)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
if (!clipboardItems.success) {
useErrorHandling().toastErrorHandler(clipboardItems.error)
return true
}

try {
useCanvasStore().getCanvas()._deserializeItems(clipboardItems.data, {})
} catch (err) {
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
console.error(err)
useErrorHandling().toastErrorHandler(err)
}
return false
return true
}

function isWorkflow(
Expand Down
23 changes: 22 additions & 1 deletion src/extensions/core/groupNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromAny, fromPartial } from '@total-typescript/shoehorn'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
import { describe, expect, it, test, vi } from 'vitest'

import { t } from '@/i18n'

Expand Down Expand Up @@ -121,6 +121,27 @@ describe('GroupNodeConfig.getLinks', () => {
const config = configFrom([], [[0, 1, 'IMAGE']])
expect(config.externalFrom).toEqual({ 0: { 1: 'IMAGE' } })
})

it('normalizes a missing primitive link type to null', () => {
const linkWithoutType = [0, 0, 1, 0, 1] satisfies GroupNodeLink
const config = configFrom([linkWithoutType])

expect(
config.getNodeDef({ index: 0, type: 'PrimitiveNode' })?.output
).toEqual([null])
})

test.for([{ unexpected: true }, ['IMAGE', 42]])(
'normalizes an invalid primitive link type to null',
(invalidType) => {
const link = [0, 0, 1, 0, 1, invalidType] satisfies GroupNodeLink
const config = configFrom([link])

expect(
config.getNodeDef({ index: 0, type: 'PrimitiveNode' })?.output
).toEqual([null])
}
)
})

describe('findUnconsumedWidgetIndex', () => {
Expand Down
Loading
Loading