mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
fix: prevent subgraph node positions from corrupting on page refresh
This commit is contained in:
@@ -181,7 +181,7 @@ describe('useVueNodeResizeTracking', () => {
|
||||
|
||||
resizeObserverState.callback?.([entry], createObserverMock())
|
||||
|
||||
expect(rectSpy).toHaveBeenCalledTimes(1)
|
||||
expect(rectSpy).not.toHaveBeenCalled()
|
||||
expect(testState.setSource).not.toHaveBeenCalled()
|
||||
expect(testState.batchUpdateNodeBounds).not.toHaveBeenCalled()
|
||||
expect(testState.syncNodeSlotLayoutsFromDOM).not.toHaveBeenCalled()
|
||||
@@ -192,13 +192,13 @@ describe('useVueNodeResizeTracking', () => {
|
||||
|
||||
resizeObserverState.callback?.([entry], createObserverMock())
|
||||
|
||||
expect(rectSpy).toHaveBeenCalledTimes(1)
|
||||
expect(rectSpy).not.toHaveBeenCalled()
|
||||
expect(testState.setSource).not.toHaveBeenCalled()
|
||||
expect(testState.batchUpdateNodeBounds).not.toHaveBeenCalled()
|
||||
expect(testState.syncNodeSlotLayoutsFromDOM).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('updates bounds on first observation when size matches but position differs', () => {
|
||||
it('uses layout store position, ignoring DOM position differences', () => {
|
||||
const nodeId = 'test-node'
|
||||
const width = 240
|
||||
const height = 180
|
||||
@@ -209,7 +209,6 @@ describe('useVueNodeResizeTracking', () => {
|
||||
left: 100,
|
||||
top: 200
|
||||
})
|
||||
const titleHeight = LiteGraph.NODE_TITLE_HEIGHT
|
||||
|
||||
seedNodeLayout({
|
||||
nodeId,
|
||||
@@ -221,20 +220,9 @@ describe('useVueNodeResizeTracking', () => {
|
||||
|
||||
resizeObserverState.callback?.([entry], createObserverMock())
|
||||
|
||||
expect(rectSpy).toHaveBeenCalledTimes(1)
|
||||
expect(testState.setSource).toHaveBeenCalledWith(LayoutSource.DOM)
|
||||
expect(testState.batchUpdateNodeBounds).toHaveBeenCalledWith([
|
||||
{
|
||||
nodeId,
|
||||
bounds: {
|
||||
x: 100,
|
||||
y: 200 + titleHeight,
|
||||
width,
|
||||
height
|
||||
}
|
||||
}
|
||||
])
|
||||
expect(testState.syncNodeSlotLayoutsFromDOM).toHaveBeenCalledWith(nodeId)
|
||||
expect(rectSpy).not.toHaveBeenCalled()
|
||||
expect(testState.setSource).not.toHaveBeenCalled()
|
||||
expect(testState.batchUpdateNodeBounds).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('updates node bounds + slot layouts when size changes', () => {
|
||||
|
||||
@@ -186,13 +186,21 @@ const resizeObserver = new ResizeObserver((entries) => {
|
||||
continue
|
||||
}
|
||||
|
||||
// Screen-space rect
|
||||
const rect = element.getBoundingClientRect()
|
||||
const [cx, cy] = conv.clientPosToCanvasPos([rect.left, rect.top])
|
||||
const topLeftCanvas = { x: cx, y: cy }
|
||||
const existingPos = nodeLayout?.position
|
||||
let posX: number
|
||||
let posY: number
|
||||
if (existingPos) {
|
||||
posX = existingPos.x
|
||||
posY = existingPos.y
|
||||
} else {
|
||||
const rect = element.getBoundingClientRect()
|
||||
const [cx, cy] = conv.clientPosToCanvasPos([rect.left, rect.top])
|
||||
posX = cx
|
||||
posY = cy + LiteGraph.NODE_TITLE_HEIGHT
|
||||
}
|
||||
const bounds: Bounds = {
|
||||
x: topLeftCanvas.x,
|
||||
y: topLeftCanvas.y + LiteGraph.NODE_TITLE_HEIGHT,
|
||||
x: posX,
|
||||
y: posY,
|
||||
width,
|
||||
height
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user