1.4 KiB
1.4 KiB
Fix Hooks Violation and Implement Waiting State
Issue
- React Hook Error: Users encountered "Rendered fewer hooks than expected" when the game started. This was caused by conditional returns in
GameRoom.tsxappearing before hook declarations (useState,useEffect). - UX Issue: Players who submitted their decks remained in the Deck Builder view, able to modify their decks, instead of seeing a waiting screen.
Fixes
- Refactored
GameRoom.tsx:- Moved all
useStateanduseEffecthooks to the top level of the component, ensuring they are always called regardless of the render logic. - Encapsulated the view switching logic into a helper function
renderContent(), which is called inside the main return statement.
- Moved all
- Implemented Waiting Screen:
- Inside
renderContent, checking if the room is indeck_buildingstatus AND if the current player hasready: true. - If ready, displays a "Deck Submitted" screen with a list of other players and their readiness status.
- Updated the sidebar player list to show a "• Ready" indicator.
- Inside
Verification
- Start a draft with multiple users (or simulate it).
- Complete draft and enter deck building.
- Submit deck as one player.
- Verify that the view changes to "Deck Submitted" / Waiting screen.
- Submit deck as the final player.
- Verify that the game starts automatically for everyone without crashing (React Error).