Refactored useWebSocket.ts to prevent SSR-related connection issues: - Created ClientState interface to encapsulate all client-only state - Added getClientState() function with lazy initialization on client only - Added SSR guards (import.meta.client) to all connection functions - Reset reactive state on client hydration to ensure clean slate - Moved heartbeatInterval and stuckStateCheckInterval into ClientState - Changed NodeJS.Timeout to ReturnType<typeof setTimeout/setInterval> - Wrapped auth watcher in import.meta.client guard Root cause: Module-level singleton state was being initialized during SSR, then persisting in a potentially corrupted state during hydration. This caused intermittent "Socket exists: no" issues where the browser wouldn't even attempt WebSocket connections. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| CLAUDE.md | ||
| useGameActions.ts | ||
| useWebSocket.ts | ||