fix(useGitWatch): skip polling on non-git cwds (closes #62)#64
Merged
milisp merged 3 commits intomilisp:masterfrom Apr 27, 2026
Merged
fix(useGitWatch): skip polling on non-git cwds (closes #62)#64milisp merged 3 commits intomilisp:masterfrom
milisp merged 3 commits intomilisp:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
🤖 Generated with Claude Code