From f54f537483402335f4f8481786284be1bff6be24 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Thu, 19 Feb 2026 00:44:19 +0000 Subject: [PATCH] Fix pingerName crash + auto-redirect returning users to last room 1. Server: pingerName was used before declaration in the WS message block (defined inside the push block). Moved declaration above both blocks. This caused all /push/request-location calls to crash with ReferenceError. 2. Landing page: always auto-redirect returning users (have saved user + last room) instead of only in standalone mode. Shows a loading spinner during redirect so the landing page doesn't flash. Co-Authored-By: Claude Opus 4.6 --- src/app/page.tsx | 20 ++++++++++++++++---- sync-server/server.js | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 5b82e73..73616a9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -25,6 +25,7 @@ export default function HomePage() { const [roomName, setRoomName] = useState(''); const [isLoaded, setIsLoaded] = useState(false); const [lastRoom, setLastRoom] = useState(null); + const [isRedirecting, setIsRedirecting] = useState(false); // Load saved user info from localStorage on mount // If opened as installed PWA (standalone mode), auto-redirect to last room @@ -45,10 +46,9 @@ export default function HomePage() { if (lastVisited) { setLastRoom(lastVisited); - // Auto-redirect if running as installed PWA and user has saved info - const isStandalone = window.matchMedia('(display-mode: standalone)').matches - || (navigator as unknown as { standalone?: boolean }).standalone === true; - if (isStandalone && stored) { + // Auto-redirect returning users to their last room + if (stored) { + setIsRedirecting(true); router.push(`/${lastVisited}`); return; } @@ -108,6 +108,18 @@ export default function HomePage() { router.push(`/${lastRoom}`); }; + // Show loading screen while redirecting to last room + if (isRedirecting) { + return ( +
+
+
+
Rejoining your map...
+
+
+ ); + } + return (
{/* ── Header Nav ─────────────────────────────────────────── */} diff --git a/sync-server/server.js b/sync-server/server.js index 90b4168..66dd662 100644 --- a/sync-server/server.js +++ b/sync-server/server.js @@ -709,6 +709,8 @@ const server = createServer(async (req, res) => { targetName = room.participants[participantId].name; } + const pingerName = callerName || 'Someone'; + // Build a set of participantIds that are currently connected via WebSocket const onlineParticipantIds = new Set(); for (const [ws, clientInfo] of clients.entries()) { @@ -754,7 +756,6 @@ const server = createServer(async (req, res) => { const subsMap = pushSubscriptions.get(roomSlug); if (subsMap && subsMap.size > 0) { const failedEndpoints = []; - const pingerName = callerName || 'Someone'; for (const [endpoint, { subscription, participantId: subParticipantId }] of subsMap.entries()) { // If targeting specific participant, skip others