fix(api): prevent main thread freeze in typing handler & fix login typo#1165
fix(api): prevent main thread freeze in typing handler & fix login typo#1165vivekyadav-3 wants to merge 2 commits intoRocketChat:developfrom
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR fixes two issues in the EmbeddedChatApi: a double-assignment typo in the login method and a blocking while loop in the typing event handler that could freeze the main thread.
Changes:
- Fixed double-assignment typo
credentials = credentials =tocredentials =in the login method - Converted handleTypingEvent from synchronous to asynchronous with non-blocking wait loop
- Added try-finally block to ensure typing handler lock is always released
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const newTypingStatus = cloneArray(this.typingUsers); | ||
| this.onTypingStatusCallbacks.forEach((callback) => | ||
| callback(newTypingStatus) | ||
| ); |
There was a problem hiding this comment.
The async method can throw errors, but there's no error handling in the try block, and callers don't await the promise. If an error occurs while manipulating typingUsers or invoking callbacks (e.g., if a callback throws), it will result in an unhandled promise rejection. Consider adding a catch block to log errors or handle them gracefully.
| ); | |
| ); | |
| } catch (error) { | |
| console.error("Error while handling typing event:", error); |
This PR addresses two issues in the @embeddedchat/api:
Typing Handler Freeze: Replaced a blocking while loop with a non-blocking async wait in
handleTypingEvent to prevent potential main thread freezes.
Login Typo: Fixed an accidental double-assignment typo in the login method