Skip to content

fix(useGitWatch): skip polling on non-git cwds (closes #62)#64

Merged
milisp merged 3 commits intomilisp:masterfrom
akakabrian:feat/usegitwatch-non-git-gate
Apr 27, 2026
Merged

fix(useGitWatch): skip polling on non-git cwds (closes #62)#64
milisp merged 3 commits intomilisp:masterfrom
akakabrian:feat/usegitwatch-non-git-gate

Conversation

@akakabrian
Copy link
Copy Markdown
Contributor

Summary

Resolves the polling loop described in #62. When cwd is a non-git directory (e.g. $HOME — common for sessions started via plain `claude`/`codex` CLI without `cd` first), `useGitWatch`'s 2.5s interval keeps firing the consumer's refresh callback. Each call hits `gitStatus` / `gitBranchInfo`, throws, and the consumer re-renders its error state — visible as a perpetual loading→error flash in `GitDiffPanel` / `RightPanelHeader`.

Adds a one-shot `isGitRepo` preflight at the top of `useGitWatch`'s effect: if cwd isn't a git repo, the watcher and the polling interval never start. `cancelled` flag handles the rare case where cwd changes mid-preflight. Cleanup unchanged — clears refs that may still be null, which is a safe no-op.

Closes #62.

Test plan

  • `bunx tsc --noEmit` clean
  • `bun run build` clean
  • cwd = a git repo → polling and watcher behave as before
  • cwd = $HOME or other non-git dir → no polling errors, no UI flash
  • Switch from non-git → git repo → polling spins up cleanly

🤖 Generated with Claude Code

akakabrian and others added 3 commits April 26, 2026 19:50
Resolves the polling loop described in milisp#62: when cwd is set to a
directory that isn't a git working tree (e.g. \$HOME, common for
sessions started via plain claude/codex CLI), useGitWatch's 2.5s
interval keeps firing the consumer's refresh callback. Each call
hits gitStatus / gitBranchInfo / etc., which throws, and the consumer
re-renders its error state. Visible as a perpetual "loading → error"
flash in GitDiffPanel and RightPanelHeader.

Adds a one-shot isGitRepo preflight at the top of the useEffect:

- Wraps the watcher + interval setup in an async initialize().
- isGitRepo(cwd) is a single gitBranchInfo round-trip with try/catch.
  Cheap and runs once per cwd change.
- If not a repo, return early — no startWatchFile, no setInterval.
- A `cancelled` flag covers the (rare) case where cwd changes while
  the preflight is in flight.
- Cleanup unchanged — clears refs that are still null when no setup
  ran, which is a safe no-op.

Consumers' one-shot refresh on cwd change still fires once and may
error, which is fine — those already wrap in try/catch and don't
loop. The polling loop was the actual noise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sibling fix to the useGitWatch polling gate: GitDiffPanel and
useGitStatsStore have their own one-shot refreshes that fire on cwd
change (independent of useGitWatch). On boot or when switching to a
non-git cwd, those throw and render an error flash before the polling
gate kicks in.

- useGitStatsStore.refreshStats: clears stats and returns when cwd
  isn't a git repo. Same UX as the !cwd branch.
- GitDiffPanel.refreshGitStatus: clears gitData/gitError/gitLoading
  and returns early on non-git cwd.

Net result: opening codexia with a non-git cwd or switching to one
shows empty git UI silently, no error flash.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The isGitRepo helper called gitBranchInfo, which routes through the
shared postJson helper that auto-renders a "Request failed" toast on
HTTP errors. So every call to isGitRepo on a non-git cwd surfaced a
red toast — visible at boot and on every cwd change.

Inline the API call with postJsonWithOptions(..., { suppressToast: true })
so the probe is silent. Tauri-desktop path is unchanged (invoke
doesn't go through the toast helper).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@milisp milisp merged commit 14825bf into milisp:master Apr 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useGitWatch consumers loop on non-git cwds, re-rendering error state every 2.5s

2 participants