From 01740afcb7c426c721544f8034ad821558609a79 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Thu, 20 Nov 2025 08:41:04 -0600 Subject: [PATCH] fix: make useArcadeSocket work without ArcadeErrorProvider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL PRODUCTION FIX - Resolves runtime error breaking all arcade games. **Problem:** - Commit 59901c55 added useArcadeError() call to useArcadeSocket - Pages not wrapped with ArcadeErrorProvider yet - Runtime error: "useArcadeError must be used within ArcadeErrorProvider" - Next.js error boundary shows generic error page with no navigation or recovery **Solution:** - Export ArcadeErrorContext from ArcadeErrorContext.tsx - Use useContext directly in useArcadeSocket instead of useArcadeError hook - Fall back to no-op function if provider not available - Allows games to work without error provider (just won't show error toasts) - Pages can be wrapped with provider incrementally in future commits **Impact:** - Fixes production runtime error immediately - Games work normally (without error toasts) - Error provider can be added to pages when ready 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- apps/web/src/contexts/ArcadeErrorContext.tsx | 2 +- apps/web/src/hooks/useArcadeSocket.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/web/src/contexts/ArcadeErrorContext.tsx b/apps/web/src/contexts/ArcadeErrorContext.tsx index 28d004be..15318615 100644 --- a/apps/web/src/contexts/ArcadeErrorContext.tsx +++ b/apps/web/src/contexts/ArcadeErrorContext.tsx @@ -7,7 +7,7 @@ interface ArcadeErrorContextValue { addError: (message: string, details?: string) => void } -const ArcadeErrorContext = createContext(null) +export const ArcadeErrorContext = createContext(null) /** * Provider for arcade error management diff --git a/apps/web/src/hooks/useArcadeSocket.ts b/apps/web/src/hooks/useArcadeSocket.ts index 53c0e3b6..39440baf 100644 --- a/apps/web/src/hooks/useArcadeSocket.ts +++ b/apps/web/src/hooks/useArcadeSocket.ts @@ -1,7 +1,7 @@ -import { useCallback, useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useRef, useState, useContext } from 'react' import { io, type Socket } from 'socket.io-client' import type { GameMove } from '@/lib/arcade/validation' -import { useArcadeError } from '@/contexts/ArcadeErrorContext' +import { ArcadeErrorContext } from '@/contexts/ArcadeErrorContext' export interface ArcadeSocketEvents { onSessionState?: (data: { @@ -39,7 +39,10 @@ export function useArcadeSocket(events: ArcadeSocketEvents = {}): UseArcadeSocke const [socket, setSocket] = useState(null) const [connected, setConnected] = useState(false) const eventsRef = useRef(events) - const { addError } = useArcadeError() + + // Get error context if available, but don't throw if it's not + const errorContext = useContext(ArcadeErrorContext) + const addError = errorContext?.addError || (() => {}) // Update events ref when they change useEffect(() => {