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-icons): gate the github avatar probe on the active section

enes4ee81030a7c3
diff --git a/src/renderer/components/settings/ProjectIconPicker.test.tsx b/src/renderer/components/settings/ProjectIconPicker.test.tsx
index 751dd8c22..3b58b05e2 100644
--- a/src/renderer/components/settings/ProjectIconPicker.test.tsx
+++ b/src/renderer/components/settings/ProjectIconPicker.test.tsx
@@ -229,4 +229,46 @@ describe('ProjectIconPicker', () => {
await flush()
expect(projectAvatar).toHaveBeenCalledTimes(1)
})
+
+ // A settings SEARCH mounts every matching project's picker, but only ONE section is active.
+ const renderActive = async (active: boolean): Promise<void> => {
+ await act(async () => {
+ root.render(
+ <ProjectIconPicker
+ projectId="p1"
+ name="Alpha"
+ icon={undefined}
+ color="#0a84ff"
+ colors={COLORS}
+ dark
+ active={active}
+ onIcon={onIcon}
+ onColor={onColor}
+ />
+ )
+ })
+ }
+
+ it('does NOT probe while the section is visible-but-not-active (a search match)', async () => {
+ const projectAvatar = vi.fn(async () => ({ dataUrl: 'data:image/png;base64,AV==' }))
+ useAvatar(projectAvatar)
+ root = createRoot(host)
+ await renderActive(false)
+ await flush()
+ expect(projectAvatar).not.toHaveBeenCalled()
+ expect(tab('Avatar').disabled).toBe(true)
+ })
+
+ it('probes once when the section becomes active (the real open)', async () => {
+ const projectAvatar = vi.fn(async () => ({ dataUrl: 'data:image/png;base64,AV==' }))
+ useAvatar(projectAvatar)
+ root = createRoot(host)
+ await renderActive(false)
+ await flush()
+ expect(projectAvatar).not.toHaveBeenCalled()
+ await renderActive(true)
+ await flush()
+ expect(projectAvatar).toHaveBeenCalledTimes(1)
+ expect(tab('Avatar').disabled).toBe(false)
+ })
})
diff --git a/src/renderer/components/settings/ProjectIconPicker.tsx b/src/renderer/components/settings/ProjectIconPicker.tsx
index fea06d89b..a60d6e75c 100644
--- a/src/renderer/components/settings/ProjectIconPicker.tsx
+++ b/src/renderer/components/settings/ProjectIconPicker.tsx
@@ -27,6 +27,13 @@ export interface ProjectIconPickerProps {
colors: readonly string[]
/** App's resolved appearance — forced onto the emoji picker rather than its own auto. */
dark: boolean
+ /**
+ * Whether this project's section is the one the user is actively viewing. The GitHub-avatar probe
+ * is gated on this: a settings SEARCH mounts every matching project's picker (`sectionVisible`),
+ * but only ONE is active — probing on bare mount would fire an uncached live API call per project.
+ * Defaults to true so a standalone picker (no search shell) still probes on open.
+ */
+ active?: boolean
onIcon: (icon: ProjectIcon | undefined) => void
onColor: (color: string) => void
}
@@ -40,6 +47,7 @@ export function ProjectIconPicker({
color,
colors,
dark,
+ active = true,
onIcon,
onColor
}: ProjectIconPickerProps): React.JSX.Element {
@@ -72,8 +80,12 @@ export function ProjectIconPicker({
// origin resolves → reveal the Avatar tab; if the stored icon is a github avatar whose bytes have
// drifted, quietly re-commit the fresh src. ANTI-CLOBBER: a null/failed resolve touches nothing —
// it must never blank an already-set github icon, and a no-origin project simply keeps the tab
- // hidden. Fires only here (mount / projectId change) — never on a timer or on every render.
+ // hidden. Gated on `active`: during a settings SEARCH every matching project's picker mounts, but
+ // only the ACTIVE section is the real "open" — probing on bare mount would fire one uncached live
+ // API call (credential resolve + repo detect + api.github.com + avatar fetch) PER project. So the
+ // probe fires when the section becomes active, not on mount — never on a timer or every render.
useEffect(() => {
+ if (!active) return
let cancelled = false
void (async () => {
const res = await fetchAvatar()
@@ -88,7 +100,7 @@ export function ProjectIconPicker({
cancelled = true
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [projectId])
+ }, [projectId, active])
const onUseGithubAvatar = async (): Promise<void> => {
setAvatarError(undefined)
diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
index 9187515ae..062b06db1 100644
--- a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
@@ -262,6 +262,10 @@ function EditableProjectSection({
color={project.color}
colors={NODE_COLORS}
dark={appTheme === 'dark'}
+ // Only the section the user is actually viewing probes the (uncached, live) GitHub
+ // avatar. During a settings SEARCH many sections are VISIBLE-but-not-active — gating
+ // on `active` keeps a keyword like "avatar" from firing one live API call per project.
+ active={isActive}
onIcon={(icon: ProjectIcon | undefined) => {
useProjects.getState().setProjectIcon(project.id, icon)
persistIdentityEdit()