Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor([issue-1086]): drop unused signature option from useFocusRefreshedList

Adam Eivy20529b98f579
diff --git a/client/src/hooks/useFocusRefreshedList.js b/client/src/hooks/useFocusRefreshedList.js
index 6f02ae07b3..5c8ef536a0 100644
--- a/client/src/hooks/useFocusRefreshedList.js
+++ b/client/src/hooks/useFocusRefreshedList.js
@@ -1,4 +1,4 @@
-import { useState, useEffect, useRef } from 'react';
+import { useState, useEffect } from 'react';
// Shared sidebar-list fetch pattern: load once on mount, refresh on window
// focus (debounced 30s so tab-switching doesn't hammer the API), and guard
@@ -9,22 +9,16 @@ import { useState, useEffect, useRef } from 'react';
// `fetchFn` must accept `{ silent: true }` (it owns its own error handling via
// the warn below, so the API helper should not also toast) and resolve to an
// array. Pass a stable function reference (a module-level `api.*` export is
-// stable). The `signature`/`label` options are read through refs so an inline
-// arrow doesn't re-arm the effect (and double-fetch) on every render.
-const defaultSignature = (item) => `${item.id}|${item.name}`;
+// stable); `label` is a plain string used only in the warn message.
+const sigOf = (list) => list.map((item) => `${item.id}|${item.name}`).join('||');
const byName = (a, b) =>
(a.name || '').localeCompare(b.name || '', undefined, { sensitivity: 'base' });
-export function useFocusRefreshedList(fetchFn, { signature = defaultSignature, label = 'list' } = {}) {
+export function useFocusRefreshedList(fetchFn, label = 'list') {
const [items, setItems] = useState([]);
- const signatureRef = useRef(signature);
- signatureRef.current = signature;
- const labelRef = useRef(label);
- labelRef.current = label;
useEffect(() => {
let lastSuccessAt = 0;
let cancelled = false;
- const sigOf = (list) => list.map((item) => signatureRef.current(item)).join('||');
const load = () => {
fetchFn({ silent: true })
.then((result) => {
@@ -34,7 +28,7 @@ export function useFocusRefreshedList(fetchFn, { signature = defaultSignature, l
setItems((prev) => (sigOf(prev) === sigOf(next) ? prev : next));
})
.catch((err) => {
- console.warn(`⚠️ Sidebar ${labelRef.current} fetch failed: ${err?.message || err}`);
+ console.warn(`⚠️ Sidebar ${label} fetch failed: ${err?.message || err}`);
});
};
load();
@@ -47,6 +41,6 @@ export function useFocusRefreshedList(fetchFn, { signature = defaultSignature, l
cancelled = true;
window.removeEventListener('focus', onFocus);
};
- }, [fetchFn]);
+ }, [fetchFn, label]);
return items;
}
diff --git a/client/src/hooks/useFocusRefreshedList.test.jsx b/client/src/hooks/useFocusRefreshedList.test.jsx
index 741ba4938b..12325c7aeb 100644
--- a/client/src/hooks/useFocusRefreshedList.test.jsx
+++ b/client/src/hooks/useFocusRefreshedList.test.jsx
@@ -71,33 +71,17 @@ describe('useFocusRefreshedList', () => {
it('coerces a non-array result to an empty array and warns on rejection', async () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
const fetchFn = vi.fn().mockResolvedValue(null);
- const { result } = renderHook(() => useFocusRefreshedList(fetchFn, { label: 'widgets' }));
+ const { result } = renderHook(() => useFocusRefreshedList(fetchFn, 'widgets'));
await waitFor(() => expect(fetchFn).toHaveBeenCalled());
expect(result.current).toEqual([]);
const rejectFn = vi.fn().mockRejectedValue(new Error('boom'));
- renderHook(() => useFocusRefreshedList(rejectFn, { label: 'widgets' }));
+ renderHook(() => useFocusRefreshedList(rejectFn, 'widgets'));
await waitFor(() => expect(warn).toHaveBeenCalled());
expect(warn.mock.calls.some((c) => String(c[0]).includes('widgets'))).toBe(true);
warn.mockRestore();
});
- it('honors a custom signature function', async () => {
- const fetchFn = vi.fn()
- .mockResolvedValueOnce([{ id: '1', name: 'A', rev: 1 }])
- .mockResolvedValue([{ id: '1', name: 'A', rev: 2 }]);
- const { result } = renderHook(() =>
- useFocusRefreshedList(fetchFn, { signature: (i) => `${i.id}|${i.rev}` }),
- );
- await waitFor(() => expect(result.current[0].rev).toBe(1));
-
- const now = Date.now();
- vi.spyOn(Date, 'now').mockReturnValue(now + 31_000);
- fireFocus();
- // rev changed → signature differs → array replaced even though name is equal.
- await waitFor(() => expect(result.current[0].rev).toBe(2));
- });
-
it('removes the focus listener on unmount', async () => {
const fetchFn = vi.fn().mockResolvedValue([{ id: '1', name: 'A' }]);
const removeSpy = vi.spyOn(window, 'removeEventListener');
diff --git a/client/src/hooks/useSidebarSeries.js b/client/src/hooks/useSidebarSeries.js
index 99d385668b..e5b36646fc 100644
--- a/client/src/hooks/useSidebarSeries.js
+++ b/client/src/hooks/useSidebarSeries.js
@@ -5,5 +5,5 @@ import { useFocusRefreshedList } from './useFocusRefreshedList.js';
// and refreshes on window focus (debounced 30s) so freshly-created or renamed
// series surface without a reload.
export function useSidebarSeries() {
- return useFocusRefreshedList(api.listPipelineSeries, { label: 'pipeline-series' });
+ return useFocusRefreshedList(api.listPipelineSeries, 'pipeline-series');
}
diff --git a/client/src/hooks/useSidebarUniverses.js b/client/src/hooks/useSidebarUniverses.js
index 2bb0dab3e8..fa8a561c4b 100644
--- a/client/src/hooks/useSidebarUniverses.js
+++ b/client/src/hooks/useSidebarUniverses.js
@@ -5,5 +5,5 @@ import { useFocusRefreshedList } from './useFocusRefreshedList.js';
// refreshes on window focus (debounced 30s) so freshly-created or renamed
// universes surface without a reload.
export function useSidebarUniverses() {
- return useFocusRefreshedList(api.listUniverses, { label: 'universes' });
+ return useFocusRefreshedList(api.listUniverses, 'universes');
}