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 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-02-19 00:44:19 +00:00
parent 53dd95fcac
commit f54f537483
2 changed files with 18 additions and 5 deletions

View File

@ -25,6 +25,7 @@ export default function HomePage() {
const [roomName, setRoomName] = useState(''); const [roomName, setRoomName] = useState('');
const [isLoaded, setIsLoaded] = useState(false); const [isLoaded, setIsLoaded] = useState(false);
const [lastRoom, setLastRoom] = useState<string | null>(null); const [lastRoom, setLastRoom] = useState<string | null>(null);
const [isRedirecting, setIsRedirecting] = useState(false);
// Load saved user info from localStorage on mount // Load saved user info from localStorage on mount
// If opened as installed PWA (standalone mode), auto-redirect to last room // If opened as installed PWA (standalone mode), auto-redirect to last room
@ -45,10 +46,9 @@ export default function HomePage() {
if (lastVisited) { if (lastVisited) {
setLastRoom(lastVisited); setLastRoom(lastVisited);
// Auto-redirect if running as installed PWA and user has saved info // Auto-redirect returning users to their last room
const isStandalone = window.matchMedia('(display-mode: standalone)').matches if (stored) {
|| (navigator as unknown as { standalone?: boolean }).standalone === true; setIsRedirecting(true);
if (isStandalone && stored) {
router.push(`/${lastVisited}`); router.push(`/${lastVisited}`);
return; return;
} }
@ -108,6 +108,18 @@ export default function HomePage() {
router.push(`/${lastRoom}`); router.push(`/${lastRoom}`);
}; };
// Show loading screen while redirecting to last room
if (isRedirecting) {
return (
<div className="min-h-screen flex items-center justify-center bg-slate-900">
<div className="text-center">
<div className="w-8 h-8 border-2 border-emerald-500 border-t-transparent rounded-full animate-spin mx-auto mb-4" />
<div className="text-white/60">Rejoining your map...</div>
</div>
</div>
);
}
return ( return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900"> <div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900">
{/* ── Header Nav ─────────────────────────────────────────── */} {/* ── Header Nav ─────────────────────────────────────────── */}

View File

@ -709,6 +709,8 @@ const server = createServer(async (req, res) => {
targetName = room.participants[participantId].name; targetName = room.participants[participantId].name;
} }
const pingerName = callerName || 'Someone';
// Build a set of participantIds that are currently connected via WebSocket // Build a set of participantIds that are currently connected via WebSocket
const onlineParticipantIds = new Set(); const onlineParticipantIds = new Set();
for (const [ws, clientInfo] of clients.entries()) { for (const [ws, clientInfo] of clients.entries()) {
@ -754,7 +756,6 @@ const server = createServer(async (req, res) => {
const subsMap = pushSubscriptions.get(roomSlug); const subsMap = pushSubscriptions.get(roomSlug);
if (subsMap && subsMap.size > 0) { if (subsMap && subsMap.size > 0) {
const failedEndpoints = []; const failedEndpoints = [];
const pingerName = callerName || 'Someone';
for (const [endpoint, { subscription, participantId: subParticipantId }] of subsMap.entries()) { for (const [endpoint, { subscription, participantId: subParticipantId }] of subsMap.entries()) {
// If targeting specific participant, skip others // If targeting specific participant, skip others