Skip to content
Closed
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
318 changes: 318 additions & 0 deletions docs/architecture/ecs/ecs-component-entity-data-audit.md

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions docs/architecture/ecs/ecs-extension-compatibility-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ Derived first-party rows are recomputed on read; extension entries remain on
### Persistence hooks

`node.onSerialize`, `node.onConfigure`, `graph.onSerialize`, and
`graph.onConfigure` remain compatibility surfaces, but currently expose full
node/workflow DTOs or live objects. Extensions can therefore mutate canonical
store-backed persistence fields outside store actions.
The migration must measure this usage before replacing it with a controlled
adapter for validated, namespaced plain-data payloads. This phase requires the
adapter to define serialization and configuration behavior without allowing
extension payload hooks to rewrite canonical fields. Replay and command-based
undo contracts are later architecture work.
`graph.onConfigure` remain compatibility surfaces. Serialize hooks receive a
mutable DTO view: changes to canonical fields are applied to that serialization,
while JSON-compatible noncanonical fields are persisted under `extensions`.
Configure hooks receive an isolated clone containing canonical data plus the
owner's extension payload; mutating that clone does not reconfigure the graph.

Extensions should persist JSON-compatible data under a unique key in
`data.extensions` and read it from the same key in `onConfigure`. Legacy flat
fields are still projected into configure views, but migrate them to a
namespaced key. Do not use `onConfigure` to rewrite nodes, links, or other
canonical workflow fields; perform graph mutations through supported graph APIs
after configuration instead.

### Custom-widget constructors

Expand Down
159 changes: 47 additions & 112 deletions docs/architecture/ecs/ecs-migration-plan.md

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions src/components/breadcrumb/SubgraphBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import Breadcrumb from 'primevue/breadcrumb'
import Button from 'primevue/button'
import type { MenuItem } from 'primevue/menuitem'
import { computed, onUpdated, ref, watch } from 'vue'
import { computed, onBeforeUnmount, onMounted, onUpdated, ref } from 'vue'

import SubgraphBreadcrumbItem from '@/components/breadcrumb/SubgraphBreadcrumbItem.vue'
import WorkflowActionsDropdown from '@/components/common/WorkflowActionsDropdown.vue'
Expand Down Expand Up @@ -135,20 +135,14 @@ const handleBackClick = () => {
void useCommandStore().execute('Comfy.Graph.ExitSubgraph')
}

const breadcrumbElement = computed(() => {
if (!breadcrumbRef.value) return null

const el = (breadcrumbRef.value as unknown as { $el: HTMLElement }).$el
const list = el?.querySelector('.p-breadcrumb-list') as HTMLElement
return list
})

// Check for overflow on breadcrumb items and collapse/expand the breadcrumb to fit
let overflowObserver: ReturnType<typeof useOverflowObserver> | undefined
watch(breadcrumbElement, (el) => {
overflowObserver?.dispose()
overflowObserver = undefined
onMounted(() => {
const breadcrumb = breadcrumbRef.value
if (!breadcrumb) return

const root = (breadcrumb as unknown as { $el: HTMLElement }).$el
const el = root.querySelector<HTMLElement>('.p-breadcrumb-list')
if (!el) return

overflowObserver = useOverflowObserver(el, {
Expand Down Expand Up @@ -193,6 +187,8 @@ watch(breadcrumbElement, (el) => {
})
})

onBeforeUnmount(() => overflowObserver?.dispose())

// If e.g. the workflow name changes, we need to check the overflow again
onUpdated(() => {
if (!overflowObserver?.disposed.value) {
Expand Down
2 changes: 0 additions & 2 deletions src/components/graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ watch(
)

watchEffect((onCleanup) => {
if (!shouldRenderVueNodes.value) return

const canvas = canvasStore.canvas
if (canvas) onCleanup(notifyLayoutChanges(canvas))
})
Expand Down
55 changes: 6 additions & 49 deletions src/components/maskeditor/BrushCursor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from '@testing-library/vue'
import { nextTick, reactive } from 'vue'
import { render, screen, waitFor } from '@testing-library/vue'
import { reactive } from 'vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import BrushCursor from '@/components/maskeditor/BrushCursor.vue'
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('BrushCursor', () => {
expect(style).toContain('top: 305px')
})

it('should subtract container offset when containerRef is provided', () => {
it('should subtract container offset when containerRef is provided', async () => {
mockStore.cursorPoint = { x: 200, y: 300 }
mockStore.panOffset = { x: 0, y: 0 }
mockStore.brushSettings.size = 20
Expand All @@ -136,55 +136,12 @@ describe('BrushCursor', () => {
renderCursor(container)

// left = 200 + 0 - 20 - 30 = 150; top = 300 + 0 - 20 - 60 = 220
await waitFor(() => {
expect(styleOf(getBrushEl())).toContain('left: 150px')
})
const style = styleOf(getBrushEl())
expect(style).toContain('left: 150px')
expect(style).toContain('top: 220px')
})

it('should read the container rect once per position, not once per axis', async () => {
mockStore.cursorPoint = { x: 200, y: 300 }
mockStore.panOffset = { x: 0, y: 0 }
mockStore.brushSettings.size = 20
mockStore.brushSettings.hardness = 1
mockStore.zoomRatio = 1

const container = document.createElement('div')
const readRect = vi
.spyOn(container, 'getBoundingClientRect')
.mockReturnValue({
left: 30,
top: 60,
right: 0,
bottom: 0,
width: 0,
height: 0,
x: 0,
y: 0,
toJSON: () => ({})
} as DOMRect)

renderCursor(container)

// `getBoundingClientRect` forces a synchronous layout and the cursor
// moves on every mousemove, so reading it per axis doubled the cost for
// one rect.
expect(
readRect,
'left and top come from the same rect; reading it twice is two forced layouts per mousemove'
).toHaveBeenCalledTimes(1)

mockStore.cursorPoint = { x: 201, y: 301 }
await nextTick()

// The other half of the guarantee, and the one that keeps the offset
// correct while the dialog is dragged: a DOMRect is not reactive, so
// caching it across moves would pass the assertion above and silently
// stop tracking the container.
expect(
readRect,
'a moved cursor must re-read the rect; a cached one goes stale the moment the dialog moves'
).toHaveBeenCalledTimes(2)
})
})

describe('gradient preview', () => {
Expand Down
46 changes: 18 additions & 28 deletions src/components/maskeditor/BrushCursor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</template>

<script setup lang="ts">
import { useElementBounding } from '@vueuse/core'
import { computed } from 'vue'

import {
Expand All @@ -40,6 +41,8 @@ const { containerRef } = defineProps<{
}>()

const store = useMaskEditorStore()
const { left: containerOffsetLeft, top: containerOffsetTop } =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD FIX — this loses the property the deleted comment was specifically protecting.

The old code re-read getBoundingClientRect() inside a computed over cursorPoint, and the comment said in as many words that this was deliberate "to keep the offset correct while the dialog is dragged or resized".

useElementBounding recomputes on: ResizeObserver of the target, window resize, window scroll (capture), and a MutationObserver on the target's own style/class attributes. Dragging the mask-editor dialog moves an ancestor — containerRef is MaskEditorContent's root, not the dialog root — so none of those fire. left/top go stale and the brush cursor draws offset by the drag delta.

Resize is covered; drag is not. Either observe the dialog root as well, or recompute on pointermove (throttled) instead of per-cursor-point.

Separately: this change and the WorkflowTabs / SubgraphBreadcrumb ones are unrelated lint cleanups riding along in an ECS refactor — they belong in their own PR where a mask-editor regression would actually be looked for.

useElementBounding(() => containerRef)

const brushOpacity = computed(() => {
return store.brushVisible ? 1 : 0
Expand All @@ -56,36 +59,23 @@ const brushSize = computed(() => {
return brushRadius.value * 2
})

/**
* One rect read per move, not one per axis. `cursorPoint` changes on every
* mousemove and `getBoundingClientRect` forces layout, so reading it separately
* in `brushLeft` and `brushTop` cost two synchronous layouts per event for a
* single rect.
*
* The read is deliberately still inside a computed over `cursorPoint`: the rect
* is not reactive, and re-reading it as the cursor moves is what keeps the
* offset correct while the dialog is dragged or resized. This halves the reads
* without changing when they happen.
*/
const brushPosition = computed(() => {
const dialogRect = containerRef?.getBoundingClientRect()
return {
left:
store.cursorPoint.x +
store.panOffset.x -
brushRadius.value -
(dialogRect?.left || 0),
top:
store.cursorPoint.y +
store.panOffset.y -
brushRadius.value -
(dialogRect?.top || 0)
}
const brushLeft = computed(() => {
return (
store.cursorPoint.x +
store.panOffset.x -
brushRadius.value -
containerOffsetLeft.value
)
})

const brushLeft = computed(() => brushPosition.value.left)

const brushTop = computed(() => brushPosition.value.top)
const brushTop = computed(() => {
return (
store.cursorPoint.y +
store.panOffset.y -
brushRadius.value -
containerOffsetTop.value
)
})

const borderRadius = computed(() => {
return store.brushSettings.type === BrushShape.Rect ? '0%' : '50%'
Expand Down
9 changes: 5 additions & 4 deletions src/components/rightSidePanel/RightSidePanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function renderPanel(
rootGraph: LGraph
currentGraph: LGraph
node: LGraphNode
}
},
pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false })
) {
const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false })
setActivePinia(pinia)

const rootGraph = graphContext?.rootGraph ?? new LGraph()
Expand Down Expand Up @@ -173,7 +173,8 @@ describe('RightSidePanel active tab fallback', () => {
})

it('keeps errors active for a pending subgraph interior node scan', () => {
setActivePinia(createTestingPinia({ createSpy: vi.fn, stubActions: false }))
const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false })
setActivePinia(pinia)
const subgraph = createTestSubgraph()
const node = new LGraphNode('CheckpointLoaderSimple')
node.id = toNodeId(7)
Expand All @@ -183,7 +184,7 @@ describe('RightSidePanel active tab fallback', () => {
rootGraph.add(host)

const { executionErrorStore, executionId, openPanel, rightSidePanelStore } =
renderPanel('errors', { rootGraph, currentGraph: subgraph, node })
renderPanel('errors', { rootGraph, currentGraph: subgraph, node }, pinia)

expect(
executionErrorStore.hasPendingAddedNodeErrorScan(rootGraph, executionId)
Expand Down
9 changes: 6 additions & 3 deletions src/components/rightSidePanel/subgraph/SubgraphEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import AsyncSearchInput from '@/components/ui/search-input/AsyncSearchInput.vue'
import { useLitegraphService } from '@/services/litegraphService'
import { usePreviewExposureStore } from '@/stores/previewExposureStore'
import {
getPreviewExposureHostLocator,
usePreviewExposureStore
} from '@/stores/previewExposureStore'
import { useRightSidePanelStore } from '@/stores/workspace/rightSidePanelStore'
import { cn } from '@comfyorg/tailwind-utils'

Expand Down Expand Up @@ -114,7 +117,7 @@ const activePromotedRows = computed<PromotedRow[]>({
})

function getActivePreviewRows(node: SubgraphNode): PreviewRow[] {
const hostLocator = String(node.id)
const hostLocator = getPreviewExposureHostLocator(node)
const rootGraphId = node.rootGraph.id
const exposures = previewExposureStore.getExposures(rootGraphId, hostLocator)
return exposures.flatMap((exposure): PreviewRow[] => {
Expand Down Expand Up @@ -283,7 +286,7 @@ function demoteRow(row: ActiveRow) {
}
previewExposureStore.removeExposure(
subgraphNode.rootGraph.id,
String(subgraphNode.id),
getPreviewExposureHostLocator(subgraphNode),
row.exposure.name
)
refreshActiveNodeRendering()
Expand Down
Loading
Loading