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: a no-op font step leaves the projects store untouched (#915)

Erik Zwep3ef9f9d08997
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index e1cf62ccf..2efb7cd6c 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -260,7 +260,7 @@ import {
forwardedResetMatches,
nextTerminalFontSizeOverride,
normalizeTerminalFontSize,
- patchStoredFontSize,
+ patchProjectFontSize,
requestTerminalFontZoom,
type TerminalFontZoomRequest
} from '../terminal/terminal-font-zoom'
@@ -9627,13 +9627,11 @@ export function Canvas() {
// Same epoch guard as `commitActiveToStore`; the next commit writes the identical value.
const activeId = useProjects.getState().activeProjectId
if (activeId && canCommitCanvas(nodesProjectIdRef.current, activeId)) {
- useProjects.setState((st) => ({
- projects: st.projects.map((p) => {
- if (p.id !== activeId) return p
- const nodes = patchStoredFontSize(p.nodes, d.nodeId, next)
- return nodes === p.nodes ? p : { ...p, nodes }
- })
- }))
+ useProjects.setState((st) => {
+ const projects = patchProjectFontSize(st.projects, activeId, d.nodeId, next)
+ // A no-op step returns the same array: hand back the same state so nothing re-renders.
+ return projects === st.projects ? st : { projects }
+ })
}
markDirty()
}
diff --git a/src/renderer/terminal/terminal-font-zoom.test.ts b/src/renderer/terminal/terminal-font-zoom.test.ts
index 823b453ca..60a7d714c 100644
--- a/src/renderer/terminal/terminal-font-zoom.test.ts
+++ b/src/renderer/terminal/terminal-font-zoom.test.ts
@@ -12,6 +12,7 @@ import {
nextTerminalFontSizeOverride,
normalizeTerminalFontSize,
patchStoredFontSize,
+ patchProjectFontSize,
requestTerminalFontZoom,
terminalFontZoomAction,
terminalFontZoomChord,
@@ -252,3 +253,21 @@ describe('patchStoredFontSize (review round 3: Omni Kanban reads the projects st
expect(patchStoredFontSize(nodes, 'missing', 20)).toBe(nodes)
})
})
+
+describe('patchProjectFontSize (the store-level patch the Omni mirror applies)', () => {
+ const projects = [
+ { id: 'p1', nodes: [{ id: 'a', terminalFontSize: 15 }] },
+ { id: 'p2', nodes: [{ id: 'a' }] }
+ ]
+ it('patches only the named project, reusing every other project object', () => {
+ const out = patchProjectFontSize(projects, 'p1', 'a', 16)
+ expect(out).not.toBe(projects)
+ expect(out[0].nodes).toEqual([{ id: 'a', terminalFontSize: 16 }])
+ expect(out[1]).toBe(projects[1])
+ })
+ it('returns the SAME projects array for a no-op step, so the store does not notify', () => {
+ expect(patchProjectFontSize(projects, 'p1', 'a', 15)).toBe(projects)
+ expect(patchProjectFontSize(projects, 'p1', 'missing', 20)).toBe(projects)
+ expect(patchProjectFontSize(projects, 'nope', 'a', 20)).toBe(projects)
+ })
+})
diff --git a/src/renderer/terminal/terminal-font-zoom.ts b/src/renderer/terminal/terminal-font-zoom.ts
index 7f8f50e8e..37b966ebd 100644
--- a/src/renderer/terminal/terminal-font-zoom.ts
+++ b/src/renderer/terminal/terminal-font-zoom.ts
@@ -197,6 +197,25 @@ export function patchStoredFontSize<T extends { id: string; terminalFontSize?: n
return out
}
+/**
+ * PURE: `patchStoredFontSize` lifted to the projects list — only `projectId` is touched, and a
+ * no-op step (node missing, value unchanged, project unknown) returns the SAME array, so the
+ * store's `setState` sees no change and notifies nobody (review: a fresh `projects.map` on every
+ * clamped or repeated step re-rendered the Omni board for nothing).
+ */
+export function patchProjectFontSize<
+ N extends { id: string; terminalFontSize?: number },
+ P extends { id: string; nodes: N[] }
+>(projects: P[], projectId: string, nodeId: string, next: number | undefined): P[] {
+ const i = projects.findIndex((p) => p.id === projectId)
+ if (i < 0) return projects
+ const nodes = patchStoredFontSize(projects[i].nodes, nodeId, next)
+ if (nodes === projects[i].nodes) return projects
+ const out = projects.slice()
+ out[i] = { ...projects[i], nodes }
+ return out
+}
+
/** Stamped on each terminal's xterm host (canvas node and card modal) with the node id. */
export const FONT_ZOOM_NODE_ATTR = 'data-font-zoom-node'
diff --git a/src/renderer/terminal/terminal-font-zoom.wiring.test.ts b/src/renderer/terminal/terminal-font-zoom.wiring.test.ts
index 499a7a7d9..456a90a2a 100644
--- a/src/renderer/terminal/terminal-font-zoom.wiring.test.ts
+++ b/src/renderer/terminal/terminal-font-zoom.wiring.test.ts
@@ -124,7 +124,7 @@ describe('terminal font zoom — key wiring', () => {
it('mirrors the step into the projects store so the Omni board (which reads it) updates live', () => {
const start = CANVAS.indexOf('TERMINAL_FONT_ZOOM_EVENT, onFontZoom')
const body = CANVAS.slice(CANVAS.lastIndexOf('useEffect(', start), start)
- expect(body).toContain('patchStoredFontSize(')
+ expect(body).toContain('patchProjectFontSize(')
// Same epoch guard commitActiveToStore uses: never patch another project's stored nodes.
expect(body).toContain('canCommitCanvas(nodesProjectIdRef.current,')
})