You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When invoking removeAllListeners to clean up event listeners, the event listeners for onAdd and onRemove are not cleared, resulting in multiple invocations.
Optional: Minimal reproduction
export const Provider = ({ children }: { children: ReactNode }) => {
const [currentRoom, setCurrentRoom] = useState<Room<State> | null>(null);
useEffect(() => {
if (!currentRoom) {
return;
}
log.info('registerRoomListeners', currentRoom.roomId);
currentRoom.onLeave(onRoomLeave);
currentRoom.onError(onRoomError);
// currentRoom.onStateChange(onStateChange);
currentRoom.onMessage('__playground_message_types', onPlaygroundMessage);
// FIXME: onAdd and onRemove is getting called multiple times after hot-reload
currentRoom.state.players.onAdd(onPlayerEnter);
currentRoom.state.players.onRemove(onPlayerLeave);
currentRoom.state.viewers.onAdd(onViewerEnter);
currentRoom.state.viewers.onRemove(onViewerLeave);
return () => {
if (currentRoom) {
log.info('unregisterRoomListeners', currentRoom.roomId);
currentRoom.removeAllListeners();
}
};
}, [
currentRoom,
onRoomLeave,
onRoomError,
onPlaygroundMessage,
onPlayerEnter,
onPlayerLeave,
onViewerEnter,
onViewerLeave,
]);
return <>{children}</>;
};
The text was updated successfully, but these errors were encountered:
Bug description
When invoking removeAllListeners to clean up event listeners, the event listeners for onAdd and onRemove are not cleared, resulting in multiple invocations.
Optional: Minimal reproduction
The text was updated successfully, but these errors were encountered: