diff --git a/src/contexts/room-context.tsx b/src/contexts/room-context.tsx index 0c36d56..09490bf 100644 --- a/src/contexts/room-context.tsx +++ b/src/contexts/room-context.tsx @@ -248,7 +248,11 @@ export function RoomProvider({ if (client.getStatus() !== 'open') { await client.connect(); } - await client.subscribeRoom(activeRoomId); + // Re-check: activeRoomId may have changed while we were waiting for connect. + // Use activeRoomIdRef to get the *current* room, not the stale closure value. + const roomId = activeRoomIdRef.current; + if (!roomId) return; + await client.subscribeRoom(roomId); loadMoreRef.current?.(null); }; setup();