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]);