DUP-TS-2: useWorkingTreeDiff reimplements useDebouncedSessionResource #40

Closed
opened 2026-05-27 16:56:43 +02:00 by dries · 0 comments
Owner

Summary

frontend/src/lib/useWorkingTreeDiff.ts (152 lines) manually re-implements the entire debounced-fetch machinery already present in frontend/src/lib/useDebouncedSessionResource.ts (160 lines).

Duplicated code

  • DebouncedTrigger initialisation
  • abortRef + AbortController pattern
  • Session-change reset logic
  • fetchRef indirection
  • useCallback-based refresh
  • Cleanup effects
  • Same constants: 500ms debounce, 5000ms maxWait

The comment in useWorkingTreeDiff.ts (lines 7–9) even says "Mirrors useSessionChanges".

Divergence

useWorkingTreeDiff uses dir as the key (not sessionId) and has a notRepo flag for 404 errors.

Fix

Extract a more general useDebouncedResource(key, fetchFn, emptyValue, opts) hook that both consumers call.

Effort

Medium — ~80% of code is shareable; the 404-specific notRepo flag requires care.

## Summary `frontend/src/lib/useWorkingTreeDiff.ts` (152 lines) manually re-implements the entire debounced-fetch machinery already present in `frontend/src/lib/useDebouncedSessionResource.ts` (160 lines). ## Duplicated code - `DebouncedTrigger` initialisation - `abortRef` + `AbortController` pattern - Session-change reset logic - `fetchRef` indirection - `useCallback`-based `refresh` - Cleanup effects - Same constants: 500ms debounce, 5000ms maxWait The comment in `useWorkingTreeDiff.ts` (lines 7–9) even says "Mirrors useSessionChanges". ## Divergence `useWorkingTreeDiff` uses `dir` as the key (not `sessionId`) and has a `notRepo` flag for 404 errors. ## Fix Extract a more general `useDebouncedResource(key, fetchFn, emptyValue, opts)` hook that both consumers call. ## Effort Medium — ~80% of code is shareable; the 404-specific `notRepo` flag requires care.
dries closed this issue 2026-07-11 11:23:17 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#40
No description provided.