fix(web): resolve QueryClient server-to-client error and refactor to React Query#10
Merged
Merged
Conversation
- Create QueryProvider client component wrapper - Move QueryClient instantiation to client-side component - Fix Next.js error about passing class instances to Client Components - Remove unused Move import from action-history.dto.ts
- Extract HowToPlayContent component for reusability - Fix Header component using HowToPlayContent directly - Eliminate nested modal where clicking How to Play opened another How to Play button - Maintain existing HowToPlay component for landing page compatibility
- Remove redundant position reference in setup description - Remove historical context section for cleaner, more focused content
- Add useUser hook for user state management - Add useGameQuery hook for game data fetching with polling - Add query-client configuration with retry logic - Extract data fetching logic from components into reusable hooks
- Add icon components (close, eye) for consistent UI - Add display-name-editor component for user name updates - Add board-position and game-piece components for game board - Extract reusable components from existing code
- Replace manual state management with useUser and useGameQuery hooks - Remove polling logic in favor of React Query's refetchInterval - Simplify game detail page by removing manual data fetching - Update games list page to use new hook pattern - Improve error handling and loading states
- Update Board component to work with new data structure - Update GamesList component to use React Query hooks - Improve component props and data handling - Maintain existing functionality while using new patterns
- Update API client to work with new hook patterns - Improve error handling and response types - Maintain backward compatibility with existing endpoints
- Add React imports to board-position.tsx and display-name-editor.tsx - Add global React setup in test-setup.ts for JSX support - Update games.controller.test.ts to expect includeHistory parameter - All tests now passing across web, api, and shared packages
- Fix React namespace issue by removing global declaration - Add missing boardState properties to test mock data - Fix API mock return values to match expected GameResponse type - All TypeScript errors resolved and tests passing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Problem
The application was throwing a Next.js error: "Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported." This occurred because the
QueryClientclass instance was being passed from a server component (layout.tsx) to client components.Additionally, there was a nested modal issue where clicking "How to Play" in the header would open a modal containing another "How to Play" button.
🔧 Solution
This PR addresses both issues and includes a comprehensive refactor to improve the codebase:
QueryClient Fix
QueryProviderclient component wrapper to handleQueryClientinstantiation on the client sideQueryClientfrom server component to client-side providerModal Fix
HowToPlayContentcomponent for reusabilityReact Query Migration
useUserhook for centralized user state managementuseGameQueryhook for game data fetching with automatic pollingUI Component Improvements
display-name-editorcomponent for user name updatesboard-positionandgame-piececomponents for game board📋 Changes
🧪 Testing
📝 Notes
This refactor significantly improves the codebase by:
Note
Adds action history to game APIs and refactors the web app to React Query with a client-side QueryProvider and UI/component extractions.
GET /games/:idnow accepts?includeHistory=trueand returnsactionHistoryviamapGameToGameResponse.GamesService.getActionHistorynow maps entities to response DTOs;getByIdWithDerivedStateacceptsincludeHistoryflag.ActionHistoryResponsetyping; new mappers:map-action-history-to-response.action-history.dtoand exported types; extendedGameResponsewith optionalactionHistory.QueryProviderinapp/layout.tsx; addeduseUser,useGameQuery,useGamesListQuery; migrated pagesgames/[id]andgamesto hooks with polling and improved error/loading.api.getGame(id, secret, includeHistory)and typedgetActionHistory.board-position,game-piece,display-name-editor,HowToPlayContent; updatedHeaderto use content directly (fixing nested modal).@tanstack/react-query; added query client setup (lib/query-client).Written by Cursor Bugbot for commit 9c46bbd. This will update automatically on new commits. Configure here.