Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,253 @@
import {
comfyExpect as expect,
comfyPageFixture as test
} from '@e2e/fixtures/ComfyPage'
import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
import { fitToViewInstant } from '@e2e/fixtures/utils/fitToView'
import { VueNodeFixture } from '@e2e/fixtures/utils/vueNodeFixtures'
import type { NodeId } from '@/types/nodeId'

/**
* PM-1304 / PM-1312: a Flux2ImageNode (or any node using the autogrow
* dynamic-widget system) can only be resized LARGER, never smaller, once its
* content has required more height. Switching browser tabs away and back
* re-triggers a shared measurement pipeline that re-applies this "can't
* shrink" ratchet to EVERY such node on the canvas at once, not just the one
* touched.
*
* Root cause (see graphLayoutAttachment.ts `refreshNodeGeometry` and
* useVueNodeResizeTracking.ts): the rendered node size is computed as
* `Math.max(explicitSize, contentSize)`, a floor that never decreases, and
* `contentSize` is tracked by a single module-level singleton `ResizeObserver`
* shared by every Vue node. A visibility cycle can repeat those stale
* measurements and re-latch the floor across unrelated nodes.
*/
test.describe(
'Vue Node resize ratchet on autogrow content growth',
{ tag: ['@vue-nodes', '@canvas', '@node'] },
() => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.nodeOps.clearGraph()
})

test.afterEach(async ({ comfyPage }) => {
await comfyPage.canvasOps.resetView()
})

/**
* Selects the "Flux.2 [pro]" option on a Flux2ImageNode's dynamic-combo
* `model` widget, exposing its `width`/`height`/`images` (autogrow)
* inputs. Mirrors the production widget-value setter interaction path
* (`dynamicComboWidget` in dynamicWidgets.ts), not a test-only shortcut.
*/
async function selectFluxModel(
comfyPage: ComfyPage,
nodeId: NodeId
): Promise<void> {
await comfyPage.page.evaluate((id) => {
const node = window.app!.canvas.graph!.getNodeById(id)
if (!node) throw new Error(`Node ${id} not found`)
const modelWidget = node.widgets?.find((w) => w.name === 'model')
if (!modelWidget) throw new Error('model widget not found')
modelWidget.value = 'Flux.2 [pro]'
modelWidget.callback?.(modelWidget.value)
}, nodeId)
}

/** Connects a LoadImage node's IMAGE output to the next empty autogrow
* reference-image slot on a Flux2ImageNode, using the real LiteGraph
* connect() path (exercises the same autogrow onConnectionsChange
* production code a canvas drag would). */
async function connectNextReferenceImage(
comfyPage: ComfyPage,
fluxNodeId: NodeId,
loadImageNodeId: NodeId
): Promise<void> {
await comfyPage.page.evaluate(
({ fluxNodeId, loadImageNodeId }) => {
const graph = window.app!.canvas.graph!
const fluxNode = graph.getNodeById(fluxNodeId)
const loadImage = graph.getNodeById(loadImageNodeId)
if (!fluxNode || !loadImage) throw new Error('Node not found')
const slotIndex = fluxNode.inputs.findIndex(
(input) =>
input.name.startsWith('model.images.image_') && !input.link
)
if (slotIndex === -1)
throw new Error('No empty reference-image slot found')
loadImage.connect(0, fluxNode, slotIndex)
},
{ fluxNodeId, loadImageNodeId }
)
}

/** Removes the connected reference image through LiteGraph's production
* disconnect path so the extra autogrow row is no longer intrinsically
* required before attempting to reclaim its height. */
async function disconnectReferenceImage(
comfyPage: ComfyPage,
fluxNodeId: NodeId
): Promise<void> {
await comfyPage.page.evaluate((id) => {
const node = window.app!.canvas.graph!.getNodeById(id)
if (!node) throw new Error(`Node ${id} not found`)
const slotIndex = node.inputs.findIndex(
(input) =>
input.name.startsWith('model.images.image_') && input.link != null
)
if (slotIndex === -1)
throw new Error('Connected reference-image slot not found')
node.disconnectInput(slotIndex)
}, fluxNodeId)
}

test('can shrink a node below a stale content height after it grows (PM-1304)', async ({
comfyPage
}) => {
const flux = await comfyPage.nodeOps.addNode(
'Flux2ImageNode',
undefined,
{ x: 500, y: 100 }
)
const loadImage = await comfyPage.nodeOps.addNode(
'LoadImage',
undefined,
{ x: 50, y: 100 }
)
await comfyPage.nextFrame()
await selectFluxModel(comfyPage, flux.id)
await comfyPage.nextFrame()

const node = new VueNodeFixture(
comfyPage.vueNodes.getNodeLocator(String(flux.id))
)
await expect(node.root).toBeVisible()

const baseline = (await node.boundingBox())!

// Connecting the first reference image appends a new empty autogrow
// slot, growing the node's real DOM content beyond its current
// explicit size.
await connectNextReferenceImage(comfyPage, flux.id, loadImage.id)
await comfyPage.nextFrame()

const getHeight = async () => (await node.boundingBox())?.height ?? -1
await expect.poll(getHeight).toBeGreaterThan(baseline.height)
const grownHeight = await getHeight()

// Remove the content that caused the growth. Keeping it connected would
// make grownHeight a real intrinsic minimum rather than a stale floor.
await disconnectReferenceImage(comfyPage, flux.id)
await comfyPage.nextFrame()

// The user now tries to shrink the node back down via the resize
// handle, dragging well past the original (pre-growth) height.
const handle = node.getResizeHandle('SE')
await handle.hover()
const box = await handle.boundingBox()
if (!box) throw new Error('SE resize handle has no bounding box')
const page = comfyPage.page
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(
box.x + box.width / 2,
box.y + box.height / 2 - (grownHeight - baseline.height + 60),
{ steps: 10 }
)
await page.mouse.up()
await comfyPage.nextFrame()

await expect.poll(getHeight).toBeLessThanOrEqual(grownHeight - 20)
})

test('a tab-visibility cycle does not block shrinking an untouched node (PM-1312)', async ({
comfyPage
}) => {
const fluxA = await comfyPage.nodeOps.addNode(
'Flux2ImageNode',
undefined,
{ x: 500, y: 100 }
)
const fluxB = await comfyPage.nodeOps.addNode(
'Flux2ImageNode',
undefined,
{ x: 500, y: 700 }
)
const loadImageA = await comfyPage.nodeOps.addNode(
'LoadImage',
undefined,
{ x: 50, y: 100 }
)
await comfyPage.nextFrame()
await selectFluxModel(comfyPage, fluxA.id)
await selectFluxModel(comfyPage, fluxB.id)
await comfyPage.nextFrame()
await fitToViewInstant(comfyPage)
await comfyPage.nextFrame()

const nodeA = new VueNodeFixture(
comfyPage.vueNodes.getNodeLocator(String(fluxA.id))
)
const nodeB = new VueNodeFixture(
comfyPage.vueNodes.getNodeLocator(String(fluxB.id))
)
await expect(nodeA.root).toBeVisible()
await expect(nodeB.root).toBeVisible()

const getHeightA = async () => (await nodeA.boundingBox())?.height ?? -1
const getHeightB = async () => (await nodeB.boundingBox())?.height ?? -1
const baselineB = await getHeightB()

const resizeBBy = async (deltaY: number) => {
const handle = nodeB.getResizeHandle('SE')
await handle.hover()
const box = await handle.boundingBox()
if (!box) throw new Error('SE resize handle has no bounding box')
const page = comfyPage.page
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.mouse.down()
await page.mouse.move(
box.x + box.width / 2,
box.y + box.height / 2 + deltaY,
{ steps: 10 }
)
await page.mouse.up()
await comfyPage.nextFrame()
}
// Give B explicit room above its intrinsic content floor. The cycle
// below must not prevent reclaiming some of that room.
await resizeBBy(40)
await expect.poll(getHeightB).toBeGreaterThan(baselineB + 20)

// Only node A is touched: connecting a reference image grows its
// content beyond its current explicit size.
await connectNextReferenceImage(comfyPage, fluxA.id, loadImageA.id)
await comfyPage.nextFrame()
await expect.poll(getHeightA).toBeGreaterThan(0)

// Simulate switching browser tabs away and back.
await comfyPage.page.evaluate(() => {
Object.defineProperty(document, 'visibilityState', {
configurable: true,
get: () => 'hidden'
})
document.dispatchEvent(new Event('visibilitychange'))
})
await comfyPage.nextFrame()
await comfyPage.page.evaluate(() => {
Object.defineProperty(document, 'visibilityState', {
configurable: true,
get: () => 'visible'
})
document.dispatchEvent(new Event('visibilitychange'))
})
await comfyPage.nextFrame()
await comfyPage.idleFrames(3)

const heightBAfterCycle = await getHeightB()

await resizeBBy(-20)
await expect.poll(getHeightB).toBeLessThan(heightBAfterCycle - 5)
})
}
)
10 changes: 5 additions & 5 deletions src/lib/litegraph/src/LGraphNode.geometry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('layout geometry projection', () => {
})
})

test('keeps measured geometry separate from requested size', () => {
test('lets requested size supersede a stale content measurement', () => {
const graph = new LGraph()
const node = new LGraphNode('test')
node.size = [100, 50]
Expand All @@ -192,19 +192,19 @@ describe('layout geometry projection', () => {
expect([...node.size]).toEqual([100, 50])
expect(node.serialize().size).toEqual([100, 50])
node.setSize([node.size[0] + 90, node.size[1] + 100])
expect([...node.renderingSize]).toEqual([225, 150])
expect([...node.renderingSize]).toEqual([190, 150])
const bounds: Rect = [0, 0, 0, 0]
node.measure(bounds)
expect(bounds).toEqual([
node.pos[0],
node.pos[1] - LiteGraph.NODE_TITLE_HEIGHT,
225,
190,
150 + LiteGraph.NODE_TITLE_HEIGHT
])
expect(node.serialize().size).toEqual([190, 150])
})

test('uses the attached graph for geometry and measured content', () => {
test('uses the attached graph when overriding measured content', () => {
const attachedGraph = new LGraph()
const currentGraph = new LGraph()
const node = new LGraphNode('attached')
Expand All @@ -230,7 +230,7 @@ describe('layout geometry projection', () => {
position: { x: 30, y: 40 },
size: { width: 200, height: 80 }
})
expect([...node.renderingSize]).toEqual([225, 90])
expect([...node.renderingSize]).toEqual([200, 80])
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
attachNodeLayout,
detachGraphLayouts,
detachNodeLayout,
setNodePosition
refreshNodeGeometry,
setNodePosition,
setNodeSize
} from './graphLayoutAttachment'

describe('node layout attachment ownership', () => {
Expand Down Expand Up @@ -123,3 +125,62 @@ describe('node layout attachment ownership', () => {
])
})
})

// PM-1304 / PM-1312: Flux2ImageNode (and any autogrow-widget node) can only be
// resized larger, never smaller, once its content has required more height.
// `refreshNodeGeometry` computes the rendered size as
// `Math.max(explicitSize, contentSize)`, a floor that never decreases even
// when the user explicitly drags the node smaller. Once fixed, the explicit
// size the user set via drag should win over a stale, larger content size.
describe('refreshNodeGeometry non-decreasing content-size floor (PM-1304)', () => {
beforeEach(() => {
layoutStore.resetForTests()
})

function nodeFor(graph: LGraph, id: string): LGraphNode {
const node = new LGraphNode(id)
node.id = toNodeId(id)
node.graph = graph
return node
}

it('lets an explicit resize shrink the node below a previously reported (now stale) content size', () => {
const graph = new LGraph()
const node = nodeFor(graph, 'flux-image-node')
attachNodeLayout(graph, node)

// Node starts at a small explicit size.
setNodeSize(node, [220, 100])
expect(refreshNodeGeometry(node)).toEqual([220, 100])

// An autogrow widget (e.g. a multiline prompt) reports content that
// needs more height than the explicit size, so the rendered size
// grows to fit it. This part is correct behavior.
layoutStore.reportContentSize(graph.id, node.id, {
width: 220,
height: 400
})
expect(refreshNodeGeometry(node)).toEqual([220, 400])

// The user now drags the resize handle to shrink the node back down.
// `setNodeSize` is exactly what the resize-drag interaction calls.
setNodeSize(node, [220, 120])

// Bug: the rendered size stays pinned to the stale content-size floor
// instead of honoring the user's explicit smaller size.
expect(refreshNodeGeometry(node)).toEqual([220, 120])

// ResizeObserver may immediately repeat the pre-resize measurement. It
// must remain suppressed until the content actually changes.
layoutStore.reportContentSize(graph.id, node.id, {
width: 220,
height: 400
})
expect(refreshNodeGeometry(node)).toEqual([220, 120])
layoutStore.reportContentSize(graph.id, node.id, {
width: 220,
height: 401
})
expect(refreshNodeGeometry(node)).toEqual([220, 401])
})
})
7 changes: 7 additions & 0 deletions src/renderer/core/layout/operations/graphLayoutAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ function commitNodeSize(node: LGraphNode): void {
)
return

// A direct resize is authoritative over the previous DOM measurement. Drop
// that measurement before deriving the rendered size so the node can shrink;
// ResizeObserver reports the content's new size after layout settles.
;(layoutStore as Partial<typeof layoutStore>).clearContentSize?.(
attachment.graphId,
attachment.id
)
resizeNodeLayout(node, {
width: projection.size[0],
height: projection.size[1]
Expand Down
Loading
Loading