Skip to content

fix host can't kick players - #2332

Closed
abdallahbahrawi1 wants to merge 1 commit into
openfrontio:mainfrom
abdallahbahrawi1:fix-kick-player-from-host-modal
Closed

abdallahbahrawi1 wants to merge 1 commit into
openfrontio:mainfrom
abdallahbahrawi1:fix-kick-player-from-host-modal

Conversation

@abdallahbahrawi1

Copy link
Copy Markdown
Member

Description:

Fixes an issue where the host’s “Kick” button didn’t work.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

abodcraft1

@coderabbitai

coderabbitai Bot commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The remove-player button in the lobby UI now passes its click event to the kickPlayer function with the button type explicitly set to "button". The kickPlayer function signature was extended to accept an optional event parameter, which stops event propagation and dispatches the kick action on the document instead of the element itself.

Changes

Cohort / File(s) Summary
Event handling refactor
src/client/HostLobbyModal.ts
Remove-player button forwards click events with event object; button type set to "button". kickPlayer signature extended to accept optional event parameter; now stops propagation and dispatches kick action on document instead of element.

Sequence Diagram(s)

sequenceDiagram
    participant Button as Remove-Player<br/>Button
    participant Handler as kickPlayer<br/>Handler
    participant Doc as document
    
    rect rgb(200, 220, 255)
    Note over Button,Doc: New Event Flow
    Button->>Handler: click event
    Handler->>Handler: stopPropagation()
    Handler->>Doc: dispatch kick-player<br/>on document
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review event propagation behavior change to ensure no unintended side effects in event handling chain
  • Verify that dispatching on document instead of the element properly reaches all listeners
  • Confirm the optional event parameter handling is correct and backward compatible

Possibly related PRs

Suggested labels

Feature - Frontend, UI/UX

Suggested reviewers

  • scottanderson

Poem

🎮 A button clicks with focused grace,
Event flows to a broader space—
The document now hears the call,
Propagation stops, then kicks them all! 🚀

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix host can't kick players" directly and clearly describes the main objective of the changeset. The raw summary confirms that changes to HostLobbyModal.ts fix the kick player functionality by updating the button event handling and the kickPlayer method signature. The title is concise, specific, and accurately summarizes the primary change without being vague or misleading.
Description Check ✅ Passed The PR description states "Fixes an issue where the host's 'Kick' button didn't work," which is directly related to the changeset. The raw summary confirms that the changes address exactly this issue by fixing the kick player functionality in HostLobbyModal.ts. The description is relevant and provides meaningful context about what is being fixed, meeting the lenient criteria for this check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0def339 and 4f8567b.

📒 Files selected for processing (1)
  • src/client/HostLobbyModal.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-09T02:20:43.637Z
Learnt from: VariableVince
Repo: openfrontio/OpenFrontIO PR: 1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.

Applied to files:

  • src/client/HostLobbyModal.ts
🔇 Additional comments (2)
src/client/HostLobbyModal.ts (2)

552-555: LGTM! Good defensive coding.

Passing the event to kickPlayer enables the stopPropagation call, and adding type="button" prevents unintended submit behavior. Both changes are correct.


842-854: Update comment to clarify event dispatch strategy.

The code fix is correct. The event dispatches on document and reaches the listener registered in Main.ts (line 182). Backend validation properly checks that only the lobby creator can kick other players (GameServer.ts lines 258-260) and prevents self-kicks (lines 269-270).

However, the comment mentioning "shadow DOM/slotting issues" is misleading since this component renders to light DOM. Clarify the reason for dispatching on document:

-  // Dispatch directly on document to avoid any shadow DOM/slotting issues
+  // Dispatch on document to reach the global listener in Main.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DevelopingTom DevelopingTom added this to the v27 milestone Oct 30, 2025

@DevelopingTom DevelopingTom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, but I could not ensure it is fixing the bug: while I can see the bug on openfront.io, it doesn't appear locally. Did you try it, and can you reproduce locally?

@abdallahbahrawi1

Copy link
Copy Markdown
Member Author

Thanks for the fix, but I could not ensure it is fixing the bug: while I can see the bug on openfront.io, it doesn't appear locally. Did you try it, and can you reproduce locally?

Yes i was able to see the issue, but I tested it now and it works fine !
Should I close it for now?

@jrouillard

Copy link
Copy Markdown
Contributor

main still has the issue when deployed, maybe something to do with ad layers?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants