fix: make useArcadeSocket work without ArcadeErrorProvider
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 <noreply@anthropic.com>
This commit is contained in:
parent
48d0e06a3a
commit
01740afcb7
|
|
@ -7,7 +7,7 @@ interface ArcadeErrorContextValue {
|
|||
addError: (message: string, details?: string) => void
|
||||
}
|
||||
|
||||
const ArcadeErrorContext = createContext<ArcadeErrorContextValue | null>(null)
|
||||
export const ArcadeErrorContext = createContext<ArcadeErrorContextValue | null>(null)
|
||||
|
||||
/**
|
||||
* Provider for arcade error management
|
||||
|
|
|
|||
|
|
@ -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<Socket | null>(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(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue