Fix inventory window never refreshing live (per-character version)
The inventoryVersion counter in useLiveData was a single global value that bumped on every inventory_delta for any character. With 60+ active chars all generating deltas, the global counter advanced multiple times per second. InventoryWindow's debounce effect watched this global counter, so every bump reset its 2-second fetch timer. Since bumps arrived faster than 2s, the fetch never fired — the window appeared frozen until the user closed and reopened it (which triggered the initial-fetch effect). Fix: make inventoryVersions a Map<string, number> keyed by character name. Each inventory_delta now only bumps its own character's counter, so an open window's debounce correctly fires 2s after its character's last delta, ignoring unrelated traffic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7dc5996820
commit
d26f1f725c
18 changed files with 176 additions and 9 deletions
|
|
@ -66,7 +66,7 @@ export const MapLayout: React.FC<Props> = ({ data }) => {
|
|||
selectedPlayer={selectedPlayer}
|
||||
/>
|
||||
<WindowRenderer characters={data.characters} chatMessages={data.chatMessages}
|
||||
nearbyObjects={data.nearbyObjects} inventoryVersion={data.inventoryVersion}
|
||||
nearbyObjects={data.nearbyObjects} inventoryVersions={data.inventoryVersions}
|
||||
equipmentCantrips={data.equipmentCantrips} characterStats={data.characterStats}
|
||||
socket={data.socketRef.current} />
|
||||
<RareNotification recentRares={data.recentRares} />
|
||||
|
|
|
|||
|
|
@ -17,13 +17,15 @@ interface Props {
|
|||
characters: Map<string, CharacterState>;
|
||||
chatMessages: Map<string, Array<{ text: string; color?: number; timestamp: string }>>;
|
||||
nearbyObjects: Map<string, any>;
|
||||
inventoryVersion: number;
|
||||
/** Per-character inventory counters. InventoryWindow watches only its
|
||||
* own character's value so unrelated deltas don't reset its debounce. */
|
||||
inventoryVersions: Map<string, number>;
|
||||
equipmentCantrips: Map<string, any>;
|
||||
characterStats: Map<string, any>;
|
||||
socket: WebSocket | null;
|
||||
}
|
||||
|
||||
export const WindowRenderer: React.FC<Props> = React.memo(({ characters, chatMessages, nearbyObjects, inventoryVersion, equipmentCantrips, characterStats, socket }) => {
|
||||
export const WindowRenderer: React.FC<Props> = React.memo(({ characters, chatMessages, nearbyObjects, inventoryVersions, equipmentCantrips, characterStats, socket }) => {
|
||||
const { windows } = useWindowManager();
|
||||
|
||||
return (
|
||||
|
|
@ -44,7 +46,7 @@ export const WindowRenderer: React.FC<Props> = React.memo(({ characters, chatMes
|
|||
liveStats={characterStats.get(charName)} />;
|
||||
case 'inv':
|
||||
return <InventoryWindow key={w.id} id={w.id} charName={charName} zIndex={w.zIndex}
|
||||
inventoryVersion={inventoryVersion} equipmentCantrips={equipmentCantrips.get(charName)} />;
|
||||
inventoryVersion={inventoryVersions.get(charName) ?? 0} equipmentCantrips={equipmentCantrips.get(charName)} />;
|
||||
case 'radar':
|
||||
return <RadarWindow key={w.id} id={w.id} charName={charName} zIndex={w.zIndex}
|
||||
socket={socket} radarData={nearbyObjects.get(charName) ?? null} />;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue