Skip to content

Conversation

@WeixuanZ
Copy link
Owner

@WeixuanZ WeixuanZ commented Feb 2, 2026

Performance Improvement

Optimized the PlayerCard component in PlayerList.tsx to prevent unnecessary re-renders.

Why:
The GameRoom component regenerates the players array via Object.values(activeState.players) on every render (triggered by timers, chat, or other player actions). This caused all PlayerCard components to re-render even if their data hadn't changed.

What:

  • Wrapped PlayerCard in React.memo.
  • Implemented a custom arePlayerCardPropsEqual function to compare relevant player fields (id, nickname, role, is_alive, etc.).
  • Excluded the onKick prop from comparison because it's passed as a new inline function/closure on every render, but its underlying behavior (setKickTarget) is stable.

Impact:

  • Drastically reduces the number of DOM reconciliations for the player list during active gameplay.
  • Improves UI responsiveness on lower-end devices during phase transitions and timer ticks.

Verification:

  • npm run lint passed.
  • npm run build passed.
  • Logic Verified: Custom comparator ensures re-renders only happen when visual data changes.

PR created automatically by Jules for task 426892580248412157 started by @WeixuanZ

Reduces unnecessary re-renders of the PlayerList component by memoizing PlayerCard.
The player list is derived from the global game state on every render, causing
object references to change even when data is identical.

This change:
1. Wraps PlayerCard in React.memo with a custom comparison function.
2. Checks only relevant fields (id, nickname, status, etc.) for equality.
3. Explicitly ignores the unstable `onKick` callback since its behavior is stable.

This significantly reduces rendering work during frequent state updates (e.g. timers).

Co-authored-by: WeixuanZ <39925558+WeixuanZ@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants