Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(canvas): an all-filtered node change batch no longer re-renders the canvas

enes99b65c32f437
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index e47cd7263..469482676 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -3892,6 +3892,15 @@ export function Canvas() {
}
return true
})
+ // Nothing left for the managed state: return WITHOUT calling onNodesChange. Its
+ // applyNodeChanges returns a NEW array even for an empty change list, and a new `nodes`
+ // rebuilds every ephemeral card (useMemo keyed on `nodes`) as a fresh object without
+ // `measured` — so React Flow resets its handleBounds, re-observes it, and its ResizeObserver
+ // (force: true) emits another `dimensions` change for that card, filtered out right here.
+ // MEASURED with one subagent card on a 46-node canvas: that loop re-rendered the whole
+ // Canvas every frame (60 unobserve/observe per second, ~35% of the renderer's main thread,
+ // ~110% renderer+GPU CPU with nothing happening). canvas-empty-changes.test.ts pins it.
+ if (managed.length === 0) return
// Re-snap what the resizer proposes before it is applied, so a resize tracks the grid
// during the drag instead of correcting itself on release (see lib/resizeSnap.ts).
const snapSettings = useSettings.getState().settings
diff --git a/src/renderer/canvas/canvas-empty-changes.test.ts b/src/renderer/canvas/canvas-empty-changes.test.ts
new file mode 100644
index 000000000..e9a8130c9
--- /dev/null
+++ b/src/renderer/canvas/canvas-empty-changes.test.ts
@@ -0,0 +1,22 @@
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { applyNodeChanges } from '@xyflow/react'
+
+const src = readFileSync(join(__dirname, 'Canvas.tsx'), 'utf8').replace(/\r\n/g, '\n')
+
+// An all-filtered change batch (ephemeral subagent/loop cards, keep-alive ghosts) must not reach
+// onNodesChange: see the comment at the early return in handleNodesChange.
+describe('handleNodesChange with nothing left to apply', () => {
+ it('React Flow returns a new array for an empty change list (the premise)', () => {
+ const nodes = [{ id: 'a', position: { x: 0, y: 0 }, data: {} }]
+ expect(applyNodeChanges([], nodes)).not.toBe(nodes)
+ })
+
+ it('returns before onNodesChange when every change was filtered', () => {
+ const body = src.slice(src.indexOf('const handleNodesChange'), src.indexOf('const agentIdOf'))
+ const early = body.indexOf('if (managed.length === 0) return')
+ expect(early).toBeGreaterThan(-1)
+ expect(early).toBeLessThan(body.indexOf('onNodesChange(snapped)'))
+ })
+})