From e991af208190f2abfb5129114627ef85435d8d73 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:47:45 +0000 Subject: [PATCH 1/2] Lobby: typing a room code no longer reconnects or fills browser history The socket, the address bar and the tab title followed the lobby's Room Code box, so every letter typed closed and reopened the server connection and changed the URL and title, which Chrome records as a history entry per letter (#t, #tu, #tur...). No room was joined or created: the lobby socket never sends join-room. They now follow the room you're in (liveRoomId), which only moves when you join or switch rooms. Co-Authored-By: Claude Opus 5.5 --- e2e/classroom.spec.ts | 29 +++++++++++++++++++++++++++++ src/App.tsx | 32 +++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/e2e/classroom.spec.ts b/e2e/classroom.spec.ts index f148382..95fd4c1 100644 --- a/e2e/classroom.spec.ts +++ b/e2e/classroom.spec.ts @@ -32,6 +32,35 @@ test.describe('lobby', () => { await expect(page.getByRole('button', { name: 'Lock Board' })).toHaveCount(0); }); + test('typing a room code in the lobby changes neither the address, the tab title nor the connection', async ({ page }) => { + const room = uniqueRoom('typed'); + // A socket.io handshake (a new connection) is a polling request with no session id yet. + let handshakes = 0; + page.on('request', (req) => { + const url = req.url(); + if (url.includes('/socket.io/') && !url.includes('sid=')) handshakes += 1; + }); + await page.goto('/'); + await expect(page.getByLabel('Room Code')).toBeVisible(); + await expect.poll(() => handshakes).toBeGreaterThan(0); + const before = handshakes; + + await page.getByLabel('Room Code').pressSequentially(room); + await expect(page.getByLabel('Room Code')).toHaveValue(room); + await page.waitForTimeout(500); + expect(new URL(page.url()).searchParams.get('room')).toBeNull(); + await expect(page).toHaveTitle('AllAboard'); + expect(handshakes).toBe(before); + + // Joining is what moves the address and the title to the room. + await page.getByLabel('Your Display Name').fill('Alex'); + await page.getByRole('button', { name: 'Join Classroom' }).click(); + await expect(page.locator('.konvajs-content').first()).toBeVisible(); + await expect(page).toHaveURL(new RegExp(`room=${room}`)); + await expect(page).toHaveTitle(`#${room} · AllAboard`); + await expect(page.getByPlaceholder('Message the class...')).toBeVisible(); + }); + test('a returning user is rejoined automatically after a reload', async ({ page }) => { const room = uniqueRoom('reload'); await joinRoom(page, room, 'Alex'); diff --git a/src/App.tsx b/src/App.tsx index b90cae0..2bd64b4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -313,21 +313,30 @@ export default function App() { }, [breakoutConfig.chatScope, activeBoardId, subBoards, messages]); const effectiveRoomId = normalizeRoomCode(roomId); + /** + * The room the socket, the address bar and the tab title follow: the room you're in. In the lobby it holds still + * while the Room Code box is typed in. Following the box made a new server connection, and (with the title) a + * browser-history entry, for every letter typed. + */ + const [liveRoomId, setLiveRoomId] = useState(effectiveRoomId); + useEffect(() => { + if (isJoined) setLiveRoomId(effectiveRoomId); + }, [isJoined, effectiveRoomId]); useEffect(() => { - document.title = effectiveRoomId !== 'main' ? `#${effectiveRoomId} · AllAboard` : 'AllAboard'; + document.title = liveRoomId !== 'main' ? `#${liveRoomId} · AllAboard` : 'AllAboard'; try { const url = new URL(window.location.href); - if (effectiveRoomId === 'main') { + if (liveRoomId === 'main') { url.searchParams.delete('room'); } else { - url.searchParams.set('room', effectiveRoomId); + url.searchParams.set('room', liveRoomId); } - window.history.replaceState({}, '', url.toString()); + if (url.toString() !== window.location.href) window.history.replaceState({}, '', url.toString()); } catch { // Ignore } - }, [effectiveRoomId]); + }, [liveRoomId]); useEffect(() => { const newSocket = io({ @@ -383,7 +392,7 @@ export default function App() { try { savedName = localStorage.getItem(STORAGE_KEYS.USER_NAME) || savedName; - savedPin = localStorage.getItem(STORAGE_KEYS.TEACHER_PIN_PREFIX + effectiveRoomId) || undefined; + savedPin = localStorage.getItem(STORAGE_KEYS.TEACHER_PIN_PREFIX + liveRoomId) || undefined; } catch { // Ignore storage errors } @@ -391,7 +400,7 @@ export default function App() { if (savedName && savedName.trim() && savedJoined) { const cleanSavedPin = savedPin && savedPin.trim().length >= 3 ? savedPin.trim() : undefined; newSocket.emit('join-room', { - roomId: effectiveRoomId, + roomId: liveRoomId, userId, userKey, name: savedName.trim(), @@ -456,7 +465,7 @@ export default function App() { // Ignore } } - recordRoomHistory(initRoom?.roomId || effectiveRoomId); + recordRoomHistory(initRoom?.roomId || liveRoomId); setHistoryVersion((v) => v + 1); setKickNotice(null); } @@ -924,7 +933,7 @@ export default function App() { incomingInk.clear(); newSocket.close(); }; - }, [userId, userColor, effectiveRoomId]); + }, [userId, userColor, liveRoomId]); // Teachers get live traffic only for the board they're looking at; tell the server whenever that changes // (and after every reconnect, since the server forgets per-socket state). @@ -1334,7 +1343,8 @@ export default function App() { // Ignore } setUserName(trimmedName); - if (socket && targetRoomId === effectiveRoomId) { + // Same room the socket is on: join now. Otherwise the socket reconnects for the new room and joins on connect. + if (socket && targetRoomId === liveRoomId) { socket.emit('join-room', { roomId: targetRoomId, userId, @@ -1353,7 +1363,7 @@ export default function App() { setHasEditedLobbyRoom(false); setIsJoined(true); }, - [roomId, effectiveRoomId, socket, userId, userKey, userColor] + [roomId, liveRoomId, socket, userId, userKey, userColor] ); const handleSwitchRoom = useCallback( From 5af41208a21bd46cec759d030e29291b29a2057f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:51:34 +0000 Subject: [PATCH 2/2] Lobby typing test: clear the prefilled "main" before typing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Room Code box starts with "main" at /, so typing landed in front of it ("typed-…main"). Clear it first, as a person would. Co-Authored-By: Claude Opus 5.5 --- e2e/classroom.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2e/classroom.spec.ts b/e2e/classroom.spec.ts index 95fd4c1..46b967e 100644 --- a/e2e/classroom.spec.ts +++ b/e2e/classroom.spec.ts @@ -45,6 +45,8 @@ test.describe('lobby', () => { await expect.poll(() => handshakes).toBeGreaterThan(0); const before = handshakes; + // The box starts out holding "main"; clear it, then type one letter at a time like a person would. + await page.getByLabel('Room Code').fill(''); await page.getByLabel('Room Code').pressSequentially(room); await expect(page.getByLabel('Room Code')).toHaveValue(room); await page.waitForTimeout(500);