-
Notifications
You must be signed in to change notification settings - Fork 672
feat: Vue node viewport virtualization and low-zoom level of detail to reduce DOM and rendering work in large Nodes 2.0 workflows #14119
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
Closed
r-vage
wants to merge
13
commits into
Comfy-Org:main
from
r-vage:research/viewport-virtualization-4916efd7f
Closed
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4555fac
wip: preserve viewport virtualization research
r-vage e16ce89
fix: harden Vue node viewport virtualization
r-vage 4f06df4
fix: address viewport virtualization review findings
r-vage 45c78f1
test: cover non-finite Vue node LOD scales
r-vage 007e71b
fix: address viewport virtualization review feedback
r-vage adb9bbb
Merge remote-tracking branch 'upstream/main' into research/viewport-v…
r-vage 510cddc
fix: cache viewport protected node ids
r-vage 5a068fa
Merge branch 'main' into research/viewport-virtualization-4916efd7f
r-vage 9cceafb
test: assert observable virtualization behavior
r-vage b53a4b2
Merge branch 'main' into research/viewport-virtualization-4916efd7f
r-vage b8542b8
test: ensure Vue node LOD scope cleanup
r-vage cf5ac4f
Merge branch 'main' into research/viewport-virtualization-4916efd7f
r-vage 0e35425
Merge branch 'main' into research/viewport-virtualization-4916efd7f
r-vage 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
293 changes: 293 additions & 0 deletions
293
browser_tests/tests/vueNodes/viewportVirtualization.spec.ts
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,293 @@ | ||
| import { | ||
| comfyExpect as expect, | ||
| comfyPageFixture as test | ||
| } from '@e2e/fixtures/ComfyPage' | ||
| import { toNodeId } from '@/types/nodeId' | ||
|
|
||
| test.describe( | ||
| 'Vue node viewport virtualization', | ||
| { tag: ['@vue-nodes', '@canvas'] }, | ||
| () => { | ||
| test.afterEach(async ({ comfyPage }) => { | ||
| await comfyPage.settings.setSetting( | ||
| 'Comfy.VueNodes.ViewportVirtualization', | ||
| false | ||
| ) | ||
| await comfyPage.settings.setSetting('Comfy.VueNodes.LowZoomLOD', true) | ||
| await comfyPage.settings.setSetting('Comfy.VueNodes.FullDetailZoom', 95) | ||
| await comfyPage.canvasOps.resetView() | ||
| }) | ||
|
|
||
| test('hydrates all nodes, then swaps to the settled viewport', async ({ | ||
| comfyPage | ||
| }) => { | ||
| const graphNodeIds = | ||
| await comfyPage.vueNodes.layoutNodesAndEnableVirtualization( | ||
| (_nodeId, index) => [ | ||
| index < 2 ? 100 + index * 500 : 1800 + (index - 2) * 1800, | ||
| 100 | ||
| ] | ||
| ) | ||
|
|
||
| const firstViewportIds = graphNodeIds.slice(0, 2) | ||
| await expect | ||
| .poll(() => comfyPage.vueNodes.getNodeIds()) | ||
| .toEqual(firstViewportIds) | ||
|
|
||
| await comfyPage.page.evaluate(() => { | ||
| const canvas = window.app!.canvas | ||
| canvas.ds.offset[0] = -1800 | ||
| canvas.setDirty(true, true) | ||
| }) | ||
| await comfyPage.nextFrame() | ||
|
|
||
| await expect | ||
| .poll(() => comfyPage.vueNodes.getNodeIds()) | ||
| .toEqual([graphNodeIds[2]]) | ||
| expect( | ||
| await comfyPage.page.evaluate(() => window.app!.graph.nodes.length) | ||
| ).toBe(graphNodeIds.length) | ||
| }) | ||
|
|
||
| test('keeps a multi-node drag mount set frozen during edge auto-pan', async ({ | ||
| comfyPage | ||
| }) => { | ||
| const graphNodeIds = | ||
| await comfyPage.vueNodes.layoutNodesAndEnableVirtualization( | ||
| (_nodeId, index) => [ | ||
| index < 2 ? 100 + index * 500 : 1800 + (index - 2) * 1800, | ||
| 100 | ||
| ] | ||
| ) | ||
|
|
||
| const initialIds = graphNodeIds.slice(0, 2) | ||
| await expect | ||
| .poll(() => comfyPage.vueNodes.getNodeIds()) | ||
| .toEqual(initialIds) | ||
| await comfyPage.vueNodes.selectNodes(initialIds) | ||
|
|
||
| const dragNode = comfyPage.vueNodes.getNodeLocator(initialIds[0]) | ||
| const header = dragNode.locator('.lg-node-header') | ||
| const headerBox = await header.boundingBox() | ||
| const canvasBox = await comfyPage.canvas.boundingBox() | ||
| if (!headerBox || !canvasBox) throw new Error('Drag geometry unavailable') | ||
|
|
||
| const initialOffset = await comfyPage.canvasOps.getOffset() | ||
| await comfyPage.page.mouse.move( | ||
| headerBox.x + headerBox.width / 2, | ||
| headerBox.y + headerBox.height / 2 | ||
| ) | ||
| await comfyPage.page.mouse.down() | ||
| try { | ||
| await comfyPage.page.mouse.move( | ||
| canvasBox.x + canvasBox.width - 2, | ||
| canvasBox.y + canvasBox.height / 2, | ||
| { steps: 10 } | ||
| ) | ||
| await expect | ||
| .poll(() => comfyPage.canvasOps.getOffset()) | ||
| .not.toEqual(initialOffset) | ||
| expect(await comfyPage.vueNodes.getNodeIds()).toEqual(initialIds) | ||
| } finally { | ||
| await comfyPage.page.mouse.up() | ||
| } | ||
| }) | ||
|
|
||
| test('keeps a group drag mounted until the interaction ends', async ({ | ||
| comfyPage | ||
| }) => { | ||
| await comfyPage.workflow.loadWorkflow('groups/oversized_group') | ||
| await comfyPage.page.evaluate(() => { | ||
| const group = window.app!.graph.groups[0] | ||
| group.pos = [50, 50] | ||
| group.size = [900, 825] | ||
| }) | ||
| const [nodeId] = | ||
| await comfyPage.vueNodes.layoutNodesAndEnableVirtualization(() => [ | ||
| 100, 100 | ||
| ]) | ||
| if (!nodeId) throw new Error('Expected a node in the group workflow') | ||
| await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toEqual([nodeId]) | ||
|
|
||
| await comfyPage.page.evaluate(() => { | ||
| const canvas = window.app!.canvas | ||
| const node = window.app!.graph.nodes[0] | ||
| canvas.isDragging = true | ||
| canvas.ds.offset[0] -= 1 | ||
| node.setPos(3100, 100) | ||
| node.updateArea() | ||
| canvas.setDirty(true, true) | ||
| }) | ||
| const settleDeadline = Date.now() + 200 | ||
| await expect | ||
| .poll(async () => { | ||
| if (Date.now() < settleDeadline) return [] | ||
| return await comfyPage.vueNodes.getNodeIds() | ||
| }) | ||
| .toEqual([nodeId]) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| await comfyPage.page.evaluate(() => { | ||
| window.app!.canvas.isDragging = false | ||
| window.dispatchEvent(new PointerEvent('pointerup')) | ||
| }) | ||
| await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toEqual([]) | ||
| }) | ||
|
|
||
| test('hydrates a node pasted into a distant settled viewport', async ({ | ||
| comfyPage | ||
| }) => { | ||
| const [sourceId] = | ||
| await comfyPage.vueNodes.layoutNodesAndEnableVirtualization( | ||
| (_nodeId, index) => [ | ||
| index === 0 ? 100 : 4000 + (index - 1) * 1800, | ||
| 100 | ||
| ] | ||
| ) | ||
| if (!sourceId) throw new Error('Expected a source node') | ||
|
|
||
| await expect | ||
| .poll(() => comfyPage.vueNodes.getNodeIds()) | ||
| .toEqual([sourceId]) | ||
| await comfyPage.vueNodes.getNodeLocator(sourceId).click() | ||
| await comfyPage.clipboard.copy() | ||
| await comfyPage.page.evaluate(() => { | ||
| if (document.activeElement instanceof HTMLElement) { | ||
| document.activeElement.blur() | ||
| } | ||
| }) | ||
|
|
||
| await comfyPage.page.evaluate(() => { | ||
| const canvas = window.app!.canvas | ||
| canvas.ds.offset[0] = -1800 | ||
| canvas.setDirty(true, true) | ||
| }) | ||
| const canvasBox = await comfyPage.canvas.boundingBox() | ||
| if (!canvasBox) throw new Error('Canvas geometry unavailable') | ||
| await comfyPage.page.mouse.move( | ||
| canvasBox.x + canvasBox.width / 2, | ||
| canvasBox.y + canvasBox.height / 2 | ||
| ) | ||
| await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toEqual([]) | ||
|
|
||
| const graphNodeCount = await comfyPage.page.evaluate( | ||
| () => window.app!.graph.nodes.length | ||
| ) | ||
| await comfyPage.clipboard.paste() | ||
| await expect | ||
| .poll(() => | ||
| comfyPage.page.evaluate(() => window.app!.graph.nodes.length) | ||
| ) | ||
| .toBe(graphNodeCount + 1) | ||
| await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toHaveLength(1) | ||
| }) | ||
|
|
||
| test('mounts a distant link target after auto-pan pauses', async ({ | ||
| comfyPage | ||
| }) => { | ||
| const ids = await comfyPage.page.evaluate(() => { | ||
| const graph = window.app!.graph | ||
| const source = graph.nodes.find( | ||
| (node) => node.getTitle() === 'Load Diffusion Model' | ||
| )! | ||
| const target = graph.nodes.find( | ||
| (node) => node.getTitle() === 'KSampler' | ||
| )! | ||
| const targetSlot = target.findInputSlot('model') | ||
| if (targetSlot >= 0) target.disconnectInput(targetSlot) | ||
| return { source: String(source.id), target: String(target.id) } | ||
| }) | ||
| await comfyPage.vueNodes.layoutNodesAndEnableVirtualization( | ||
| (nodeId, index) => { | ||
| if (nodeId === ids.source) return [100, 100] | ||
| if (nodeId === ids.target) return [1800, 100] | ||
| return [4000 + index * 1800, 100] | ||
| } | ||
| ) | ||
|
|
||
| await expect(comfyPage.vueNodes.getNodeLocator(ids.source)).toBeVisible() | ||
| await expect(comfyPage.vueNodes.getNodeLocator(ids.target)).toHaveCount(0) | ||
|
|
||
| const source = await comfyPage.vueNodes.getFixtureByTitle( | ||
| 'Load Diffusion Model' | ||
| ) | ||
| const sourceSlot = source.getSlot('MODEL') | ||
| const sourceBox = await sourceSlot.boundingBox() | ||
| const canvasBox = await comfyPage.canvas.boundingBox() | ||
| if (!sourceBox || !canvasBox) throw new Error('Link geometry unavailable') | ||
|
|
||
| await comfyPage.page.mouse.move( | ||
| sourceBox.x + sourceBox.width / 2, | ||
| sourceBox.y + sourceBox.height / 2 | ||
| ) | ||
| await comfyPage.page.mouse.down() | ||
| try { | ||
| await comfyPage.page.mouse.move( | ||
| canvasBox.x + canvasBox.width - 2, | ||
| canvasBox.y + canvasBox.height / 2 | ||
| ) | ||
| await expect | ||
| .poll(async () => (await comfyPage.canvasOps.getOffset())[0]) | ||
| .toBeLessThan(-1000) | ||
|
|
||
| await comfyPage.page.mouse.move( | ||
| canvasBox.x + canvasBox.width / 2, | ||
| canvasBox.y + canvasBox.height / 2 | ||
| ) | ||
| await expect( | ||
| comfyPage.vueNodes.getNodeLocator(ids.target) | ||
| ).toBeVisible() | ||
|
|
||
| const target = await comfyPage.vueNodes.getFixtureByTitle('KSampler') | ||
| const targetSlot = target.getSlot('model') | ||
| const targetBox = await targetSlot.boundingBox() | ||
| if (!targetBox) throw new Error('Target slot geometry unavailable') | ||
| await comfyPage.page.mouse.move( | ||
| targetBox.x + targetBox.width / 2, | ||
| targetBox.y + targetBox.height / 2 | ||
| ) | ||
| } finally { | ||
| await comfyPage.page.mouse.up() | ||
| } | ||
|
|
||
| await expect | ||
| .poll(() => | ||
| comfyPage.page.evaluate((targetId) => { | ||
| const target = window.app!.graph.getNodeById(targetId) | ||
| const slot = target?.findInputSlot('model') ?? -1 | ||
| return slot >= 0 ? target?.inputs[slot].link : null | ||
| }, toNodeId(ids.target)) | ||
| ) | ||
| .not.toBeNull() | ||
| }) | ||
|
|
||
| test('switches paint detail strictly below the configured zoom', async ({ | ||
| comfyPage | ||
| }) => { | ||
| await comfyPage.settings.setSetting('Comfy.VueNodes.LowZoomLOD', true) | ||
| await comfyPage.settings.setSetting('Comfy.VueNodes.FullDetailZoom', 95) | ||
| const widget = comfyPage.vueNodes.nodes.locator('.lg-node-widget').first() | ||
|
|
||
| await comfyPage.page.evaluate(() => { | ||
| window.app!.canvas.ds.scale = 0.949 | ||
| window.app!.canvas.setDirty(true, true) | ||
| }) | ||
| await expect | ||
| .poll(() => comfyPage.page.locator('html').getAttribute('class')) | ||
| .toContain('vue-nodes-low-detail') | ||
| await expect | ||
| .poll(() => widget.evaluate((el) => getComputedStyle(el).visibility)) | ||
| .toBe('hidden') | ||
|
|
||
| await comfyPage.page.evaluate(() => { | ||
| window.app!.canvas.ds.scale = 0.95 | ||
| window.app!.canvas.setDirty(true, true) | ||
| }) | ||
| await expect | ||
| .poll(() => comfyPage.page.locator('html').getAttribute('class')) | ||
| .not.toContain('vue-nodes-low-detail') | ||
| await expect | ||
| .poll(() => widget.evaluate((el) => getComputedStyle(el).visibility)) | ||
| .toBe('visible') | ||
| }) | ||
| } | ||
| ) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.