Add debug logging for inventory live-update tracing + cache-bust fetch

Temporary instrumentation to diagnose why InventoryWindow doesn't refresh
on inventory_delta. Three log points:
- useLiveData: logs when inventory_delta arrives and version bump
- InventoryWindow effect: logs every run with state
- InventoryWindow fetch: logs when debounce fires and result count

Also added cache-buster (_t=timestamp) to the refetch URL in case HTTP
caching is masking fresh data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-15 19:05:51 +02:00
parent d26f1f725c
commit 0ff396cd0e
15 changed files with 29 additions and 25 deletions

View file

@ -181,12 +181,17 @@ export const InventoryWindow: React.FC<Props> = ({ id, charName, zIndex, invento
// Debounced re-fetch on inventory_delta (no loading flash)
useEffect(() => {
console.log('[INV_DEBUG] InventoryWindow effect', { charName, inventoryVersion, initialDone: initialLoadDone.current });
if (!initialLoadDone.current || !inventoryVersion) return;
clearTimeout(debounceRef.current);
debounceRef.current = window.setTimeout(() => {
apiFetch<any>(`/inventory/${encodeURIComponent(charName)}?limit=1000`)
.then(inv => setItems((inv.items ?? []).map(normalizeItem)))
.catch(() => {});
console.log('[INV_DEBUG] debounce fired, fetching', charName);
apiFetch<any>(`/inventory/${encodeURIComponent(charName)}?limit=1000&_t=${Date.now()}`)
.then(inv => {
console.log('[INV_DEBUG] fetch result', { char: charName, count: (inv.items ?? []).length });
setItems((inv.items ?? []).map(normalizeItem));
})
.catch(err => console.log('[INV_DEBUG] fetch failed', err));
}, 2000); // 2s debounce — batch rapid deltas
return () => clearTimeout(debounceRef.current);
}, [charName, inventoryVersion]);

View file

@ -75,15 +75,14 @@ export function useLiveData(): DashboardState {
const r = msg as RareMessage;
setRecentRares(prev => [r, ...prev].slice(0, 50));
} else if (msg.type === 'inventory_delta') {
const d = msg as unknown as { character_name: string };
// Bump ONLY this character's inventory version so an open window for
// that character re-fetches. Deltas for other characters don't touch
// it, which keeps the 2s debounce in InventoryWindow from being reset
// forever by unrelated chatter.
const d = msg as unknown as { character_name: string; action?: string };
console.log('[INV_DEBUG] inventory_delta received', { char: d.character_name, action: d.action });
if (d.character_name) {
setInventoryVersions(prev => {
const next = new Map(prev);
next.set(d.character_name, (next.get(d.character_name) ?? 0) + 1);
const newVer = (next.get(d.character_name) ?? 0) + 1;
next.set(d.character_name, newVer);
console.log('[INV_DEBUG] bumped version', { char: d.character_name, newVer });
return next;
});
}