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(project-settings): hold project visuals across invalidate

enesb767608ba5ad
diff --git a/src/renderer/state/projectLaunchInfo.ts b/src/renderer/state/projectLaunchInfo.ts
index 08bbe80ac..857382f1a 100644
--- a/src/renderer/state/projectLaunchInfo.ts
+++ b/src/renderer/state/projectLaunchInfo.ts
@@ -49,13 +49,19 @@ const ENSURE_WAIT_MS = 3000
* appearance slice alone, so `useXtermVisualSettings` can subscribe shallowly to exactly what it
* renders.
*
- * Kept in lockstep with `cache` — written by the same generation-guarded branch, cleared by
- * `invalidate` — so the mirror never claims a value the cache has already dropped. Clearing on
- * invalidate does mean the panel's save path (`invalidate` then re-`ensure`) shows this machine's
- * GLOBAL appearance for the length of one round trip before the project's own comes back. That is
- * accepted deliberately: the alternative — holding the last-known value across an invalidate — keeps
- * a project's colours on screen indefinitely whenever the re-read fails, and a theme that cannot be
- * explained by any document on disk is a worse bug than a repaint the user sees correct itself.
+ * Written ONLY by `syncVisuals`, on the same generation-guarded branch that writes `cache` — and
+ * deliberately NOT cleared by `invalidateProjectLaunchInfo`. The mirror is last-known appearance,
+ * not a cache entry, and the difference matters because `invalidate` runs after EVERY project
+ * settings commit of any family: clearing here would drop the project's theme (and, with a project
+ * font, re-fit the grid of a possibly co-attached pty twice) on its way to re-reading the very
+ * document that is about to hand the same value back — a visible flash on every committed field,
+ * seconds wide on an SSH project.
+ *
+ * Holding is self-healing, which is why it needs no expiry: all three `invalidate` call sites
+ * re-`ensure` immediately, and that answer OVERWRITES this entry unconditionally — a project whose
+ * override was just deleted answers `{ theme: undefined, fontFamily: undefined }`, which clears it.
+ * The only state that can persist a stale value is one where the re-read never lands at all, and
+ * there the honest thing to show is the appearance the project last actually asked for.
*/
interface ProjectVisualsState {
byProject: Record<string, ProjectVisualOverrides>
@@ -81,16 +87,6 @@ function syncVisuals(projectId: string, info: ProjectLaunchInfo | null): void {
})
}
-/** Drop one project's mirrored appearance — its terminals fall back to the global settings until a
- * fresh answer lands. */
-function clearVisuals(projectId: string): void {
- useProjectVisuals.setState((s) => {
- if (!(projectId in s.byProject)) return s
- const { [projectId]: _dropped, ...rest } = s.byProject
- return { byProject: rest }
- })
-}
-
function currentGeneration(projectId: string): number {
return generation.get(projectId) ?? 0
}
@@ -170,7 +166,9 @@ export function ensureProjectLaunchInfo(projectId: string): Promise<void> {
* Called on `onTrustChanged` for the affected project, and after a settings-panel save. */
export function invalidateProjectLaunchInfo(projectId: string): void {
cache.delete(projectId)
- clearVisuals(projectId)
+ // NOT `useProjectVisuals`: the appearance mirror is held across an invalidate on purpose — see
+ // its doc comment. Dropping it here would repaint every terminal of the project twice on its way
+ // to re-reading the same values.
generation.set(projectId, currentGeneration(projectId) + 1)
inFlight.delete(projectId)
}
diff --git a/src/renderer/terminal/useXtermVisualSettings.test.tsx b/src/renderer/terminal/useXtermVisualSettings.test.tsx
index 455c35a0b..98d7733c5 100644
--- a/src/renderer/terminal/useXtermVisualSettings.test.tsx
+++ b/src/renderer/terminal/useXtermVisualSettings.test.tsx
@@ -202,23 +202,44 @@ describe('useXtermVisualSettings — project-scoped appearance', () => {
expect(p.renders()).toBe(afterTheme)
})
- // The accepted cost of keeping the mirror in lockstep with the cache (see its doc comment): the
- // panel's save path invalidates and immediately re-warms, so the project's terminals show this
- // machine's global appearance for the length of one round trip. Asserted rather than left to be
- // discovered — it is the visible half of the design decision.
- it('falls back to global between an invalidate and the answer that follows it', async () => {
+ // `invalidate` runs after EVERY project-settings commit, of every family — a setup-script edit
+ // invalidates too. Dropping the mirrored appearance there would repaint the project's terminals
+ // to the global theme (and, with a project font, re-fit their grids into a possibly co-attached
+ // pty) on the way to re-reading the very document that hands the same value straight back — a
+ // flash on every committed field, seconds wide on an SSH project.
+ it('holds the project theme across an invalidate, so an unrelated save does not flash', async () => {
mockLaunchInfo({ p1: info({ theme: { value: 'dracula', source: 'shared' } }) })
const p = mount('p1')
await act(async () => {
await ensureProjectLaunchInfo('p1')
})
- expect(p.theme()).toBe('dracula')
+ const settled = p.renders()
+ // What a setup-script save does: invalidate, then re-warm.
act(() => invalidateProjectLaunchInfo('p1'))
- expect(p.theme()).toBe('nord')
+ expect(p.theme()).toBe('dracula')
+ expect(p.renders()).toBe(settled) // not even a re-render, let alone a repaint
await act(async () => {
await ensureProjectLaunchInfo('p1')
})
expect(p.theme()).toBe('dracula')
+ expect(p.renders()).toBe(settled)
+ })
+
+ // Holding needs no expiry because the fresh read OVERWRITES unconditionally: this is the case
+ // that would otherwise strand a stale theme on screen — the override itself being deleted.
+ it('clears a held theme when the answer after an invalidate no longer sets one', async () => {
+ mockLaunchInfo({ p1: info({ theme: { value: 'dracula', source: 'shared' } }) })
+ const p = mount('p1')
+ await act(async () => {
+ await ensureProjectLaunchInfo('p1')
+ })
+ expect(p.theme()).toBe('dracula')
+ mockLaunchInfo({ p1: info({}) }) // the user removed the project's theme
+ act(() => invalidateProjectLaunchInfo('p1'))
+ await act(async () => {
+ await ensureProjectLaunchInfo('p1')
+ })
+ expect(p.theme()).toBe('nord') // back to this machine's global setting, once and only once
})
it('keeps following the global setting for a project that overrides nothing', async () => {