React 18 StrictMode runs effects twice on mount in dev. The previous state-based guard (joining) couldn't prevent the second invocation from firing room.join because both passes see the deferred state as null. The server accepts the first join as black, rejects the second with ROOM_FULL, and the user sees an incorrect error toast. Switching to useRef gives synchronous visibility — the second pass sees joinedCodeRef.current already set and bails. Ref is reset on .catch so a legitimate retry from the lobby isn't permanently blocked. |
||
|---|---|---|
| .. | ||
| App.tsx | ||
| index.css | ||
| main.tsx | ||