Skip to content

Fix stale roomCodeInput and autoJoinedRef when navigating between rooms#7

Closed
afraser with Copilot wants to merge 2 commits into
feat/client-test-suitefrom
copilot/sub-pr-4-another-one
Closed

Fix stale roomCodeInput and autoJoinedRef when navigating between rooms#7
afraser with Copilot wants to merge 2 commits into
feat/client-test-suitefrom
copilot/sub-pr-4-another-one

Conversation

Copilot AI commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

PeerView reuses its component instance when navigating between /listen/:roomId routes, leaving roomCodeInput showing the previous room code and autoJoinedRef permanently true, preventing auto-join from firing for subsequent rooms.

Changes

PeerView.jsx

  • Renamed initialRoomCoderoomId (live value from useParams)
  • Added a useEffect on roomId that resets all relevant state and closes any active RTCPeerConnection on navigation:
    useEffect(() => {
      setRoomCodeInput(roomId || '');
      setJoinedRoom(null);
      setConnectionState('idle');
      setError(null);
      autoJoinedRef.current = false;
      pcRef.current?.close();
      pcRef.current = null;
    }, [roomId]);
  • Auto-join effect now reads roomId directly instead of the stale captured value

PeerView.test.jsx

  • Consolidated duplicated route definitions into a shared SHARED_ROUTES constant
  • Added renderPeerViewWithNav helper (injects a NavButtons component into MemoryRouter to drive navigation without createMemoryRouter, which has an AbortSignal incompatibility with jsdom in RR v7)
  • Two new tests: navigating to a new roomId resets the input and fires a fresh auto-join; navigating to /join-room clears the input

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: afraser <1179515+afraser@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback on routing and testing in PR #4 Fix stale roomCodeInput and autoJoinedRef when navigating between rooms Mar 3, 2026
@afraser afraser closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants