Skip to content

Commit 2b40cec

Browse files
committed
fix: avoid creating persistent phantom atom for empty-string key when cwd is null
When useGitStatus(null) was called, gitStatusStateAtom('') was evaluated, permanently registering '' in knownGitStatusCwds and creating a keepAlive atom that was never garbage collected. Use a static sentinel atom for the null case to avoid touching the atom family entirely.
1 parent c7460b8 commit 2b40cec

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

apps/web/src/lib/gitStatusState.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const EMPTY_GIT_STATUS_STATE = Object.freeze<GitStatusState>({
3030
isPending: false,
3131
});
3232

33+
const EMPTY_GIT_STATUS_ATOM = Atom.make(EMPTY_GIT_STATUS_STATE).pipe(
34+
Atom.keepAlive,
35+
Atom.withLabel("git-status:null"),
36+
);
3337
const NOOP: () => void = () => undefined;
3438
const watchedGitStatuses = new Map<string, WatchedGitStatus>();
3539
const knownGitStatusCwds = new Set<string>();
@@ -126,7 +130,7 @@ export function resetGitStatusStateForTests(): void {
126130
export function useGitStatus(cwd: string | null): GitStatusState {
127131
useEffect(() => watchGitStatus(cwd), [cwd]);
128132

129-
const state = useAtomValue(gitStatusStateAtom(cwd ?? ""));
133+
const state = useAtomValue(cwd !== null ? gitStatusStateAtom(cwd) : EMPTY_GIT_STATUS_ATOM);
130134
return cwd === null ? EMPTY_GIT_STATUS_STATE : state;
131135
}
132136

0 commit comments

Comments
 (0)