-
Notifications
You must be signed in to change notification settings - Fork 757
Fixes & cleans up Username input #2619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughClears username input validation state during modal cleanup, removes event-dispatch coupling from the UsernameInput component, and tightens the username validation pattern to disallow emoji and related characters. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/client/Main.ts(1 hunks)src/client/UsernameInput.ts(0 hunks)src/core/validations/username.ts(2 hunks)
💤 Files with no reviewable changes (1)
- src/client/UsernameInput.ts
🧰 Additional context used
🧠 Learnings (2)
📚 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/Main.ts
📚 Learning: 2025-10-08T17:14:49.369Z
Learnt from: Foorack
Repo: openfrontio/OpenFrontIO PR: 2141
File: src/client/ClientGameRunner.ts:228-234
Timestamp: 2025-10-08T17:14:49.369Z
Learning: In `ClientGameRunner.ts`, the `myPlayer` field is always set when `shouldPreventWindowClose()` is called, so the null check in that method is sufficient without needing to fetch it again from `gameView.playerByClientID()`.
Applied to files:
src/client/Main.ts
🧬 Code graph analysis (1)
src/core/validations/username.ts (1)
src/client/Utils.ts (1)
translateText(92-147)
🪛 GitHub Actions: 🧪 CI
src/core/validations/username.ts
[error] 68-94: Username validation: Unicode characters (e.g., 🐈, ü) are not being accepted. Test expected validateUsername to return true for 'Cat🐈Üser' but received false.
[error] 96-132: Username sanitization: Unicode characters (e.g., Ünicode🐈Test) are being stripped/removed unexpectedly. Test expected sanitizeUsername to preserve Unicode but received output without the emoji.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Deploy to openfront.dev
🔇 Additional comments (1)
src/client/Main.ts (1)
502-512: Solid fix for the error box edge case;validationErroris a proper public contract.The
validationErrorproperty onUsernameInputis explicitly marked with the@propertydecorator (line 15 ofsrc/client/UsernameInput.ts) with typestringand default value"". This confirms:
- It's an intentional public API, not internal state
""is the correct "no error" value (used consistently in lines 63 and 65)- Clearing it before hiding the DOM element prevents re-render from restoring the error message
The pattern matches the existing direct DOM cleanup style in
Main.ts. The fix is safe and correct.
Lavodan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good just left some minor comments if we want to do it right-right.
CodeRabbit is also correct about the incorrect test, should be changed to suit the new changes
src/core/validations/username.ts
Outdated
| export const MAX_USERNAME_LENGTH = 27; | ||
|
|
||
| const validPattern = /^[a-zA-Z0-9_[\] 🐈🍀üÜ]+$/u; | ||
| const validPattern = /^[a-zA-Z0-9_[\]üÜ]+$/u; // Don't allow more than in UserNameSchema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we adhere to DRY by importing the expression from UserNameSchema, or does the logic not work in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About that, see CodeRabbits response: #2619 (comment)
Also, this PR isn't meant as a full refactor. We could still do that later on. Because now, there are several places with validation/sanitization which could be consolidated more. Maybe in the two weeks that are coming. This is just meant as a bug fix for now where single player is handled differently than multiplayer when it comes to accepting emoji (plus the not-so-clear error message for multiplayer leaves the player in the dark as to the reason).
| document.getElementById("settings-button")?.classList.add("hidden"); | ||
| if (this.usernameInput) { | ||
| // fix edge case where username-validation-error is re-rendered and hidden tag removed | ||
| this.usernameInput.validationError = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is good for the current paradigm we're using.
I'm just wondering, is there any reason to keep these elements in the DOM at all? As far as I know, the only way we handle getting the main menu back is by refreshing the page anyways, so why do we keep these elements in place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. As said above this is just meant a bugfix (and some obvious cleanup), not as a full refactor. Maybe we can do that later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
…acter in validPattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tests/Censor.test.ts (2)
108-111: Good update to reflect emoji removal.The test correctly verifies that valid Unicode characters like ü remain allowed while emoji are no longer accepted.
Consider adding an explicit test case to verify emoji rejection for clarity:
test("rejects emoji characters", () => { const res = validateUsername("User🐈Name"); expect(res.isValid).toBe(false); expect(res.error).toBe("username.invalid_chars"); });This would make the behavioral change more explicit in the test suite, though the existing "invalid chars" test on line 100 already covers this scenario.
126-126: Test input correctly updated for emoji removal.The sanitization test now verifies that Unicode characters (Ü) and spaces are preserved while invalid characters (!) are removed.
For explicit coverage of emoji handling in sanitization, consider adding a dedicated test case:
{ input: "User🐈Name", expected: "User Name" },This would clearly document how emoji are handled during sanitization (replaced/removed), though the existing test coverage should already validate this behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/validations/username.ts(2 hunks)tests/Censor.test.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/core/validations/username.ts
🧰 Additional context used
🧬 Code graph analysis (1)
tests/Censor.test.ts (1)
src/core/validations/username.ts (1)
validateUsername(97-132)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Deploy to openfront.dev
evanpelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Description:
Fix:
Error box like "Username must be at least 3 characters long" sometimes still remains after the game starts. See bug report with screenshot: https://discord.com/channels/1284581928254701718/1449169462426079343/1449169462426079343
This is while in main.ts, element username-validation-error is already set to hidden. Most of the time this works but apparently sometimes there's a re-render which removes the 'hidden' tag again. Most probable solution for this edge case: clear validationError first. Then to make sure, still hide element username-validation-error.
Cleanup username.ts:
Cleanup UserNameInput.ts:
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
tryout33