Fixes production error "Cannot read properties of undefined (reading 'carryBoxes')"
that occurred when users tried to adjust difficulty settings.
Root cause: displayRules was undefined for new users or users with old V1 config
in database. Difficulty adjustment buttons accessed displayRules.carryBoxes without
checking if displayRules existed first.
Changes:
- AdditionWorksheetClient: Initialize displayRules with defaults when missing
- ConfigPanel: Use null-coalescing operators instead of non-null assertions
- ConfigPanel: Add error logging when required fields are missing
- NEW: WorksheetErrorBoundary component to catch all errors in worksheet page
- page.tsx: Wrap client component with error boundary
This ensures users see helpful error messages instead of blank pages,
and never need to open the browser console to understand what went wrong.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Comprehensive audit of modular game system after implementing Math Sprint.
Key Findings:
- Grade: B- (down from B+ after implementation testing)
- SDK design is solid (useArcadeSession, Provider pattern)
- Unified validator registry works well
- BUT: Significant boilerplate and coupling issues
Critical Issues Identified:
1. 🚨 Database Schema Coupling - Must update schema for each game
2. ⚠️ game-config-helpers.ts - Switch statements for defaults/validation
3. ⚠️ game-configs.ts - 5 places to update per game
4. 📊 High Boilerplate Ratio - 12 files touched per game, ~44 lines boilerplate
Files That Required Updates for Math Sprint:
- 3 database schemas (arcade-rooms, arcade-sessions, room-game-configs)
- 1 API endpoint (settings/route.ts)
- 2 config files (game-configs.ts, game-config-helpers.ts)
- 2 registry files (validators.ts, game-registry.ts)
- 8 game implementation files (types, validator, provider, components, etc.)
Recommendations:
- Critical: Fix database schema to accept any string, validate at runtime
- Infer config types from game definitions (single source of truth)
- Move config validation to game definitions (eliminate switch statements)
Developer Experience:
- Time to add a game: 3-5 hours (including boilerplate)
- Pain point: Database schema updates require migration
- Pain point: Easy to forget one of the 12 files
See audit for detailed analysis and architectural recommendations.