Skip to content

Conversation

@Shreyas2004wagh
Copy link

@Shreyas2004wagh Shreyas2004wagh commented Feb 11, 2026

fix(api): prevent typing update UI freeze and improve API robustness

Acceptance Criteria fulfillment

  • Resolved critical UI unresponsiveness caused by busy-waiting in handleTypingEvent.
  • Implemented consistent error propagation across API methods using throwApiError.
  • Replaced inefficient JSON.parse(JSON.stringify(data)) with shallow object copies in message processing.
  • Ensured correct URL encoding for search queries using URLSearchParams.

Fixes #1151

PR Test Details

  • Ran: yarn workspace @embeddedchat/api build (passed).
  • Verified no typingHandlerLock / busy-wait logic remains in EmbeddedChatApi.ts.
  • Verified chat.search now builds query strings using URLSearchParams.

Copilot AI review requested due to automatic review settings February 11, 2026 15:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates EmbeddedChatApi to eliminate a UI-freezing typing busy-wait and to standardize API error handling by rethrowing caught errors, while also improving message processing and query-string encoding.

Changes:

  • Removed the handleTypingEvent busy-wait/lock to prevent UI unresponsiveness.
  • Introduced throwApiError and replaced many console.* catch handlers with consistent error propagation.
  • Replaced deep-clone (JSON.parse(JSON.stringify(...))) with shallow copies for incoming message objects and updated chat.search to use URLSearchParams.
Comments suppressed due to low confidence (1)

packages/api/src/EmbeddedChatApi.ts:1289

  • There appears to be an extra trailing blank line at the end of the file after the closing brace. If your lint/formatting rules enforce a single final newline, please remove the extra blank line(s) to avoid formatting-only diffs/noise.
}



💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

private throwApiError(error: unknown): never {
if (error instanceof Error || error instanceof ApiError) {
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

ApiError extends Error, so error instanceof Error already covers ApiError. The || error instanceof ApiError clause is redundant and can be removed to simplify the helper.

Suggested change
if (error instanceof Error || error instanceof ApiError) {
if (error instanceof Error) {

Copilot uses AI. Check for mistakes.
Comment on lines 968 to 972
});
return await response.json();
} catch (err) {
return {
error: err,
};
this.throwApiError(err);
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

pinMessage used to return an { error: ... } object on failure, but now it throws via throwApiError. There are existing call sites that check pinOrUnpin.error (e.g. packages/react/src/views/Message/Message.js) and will now crash or fail to revert optimistic UI state because the promise rejects instead of returning an object. Please either keep the previous return-shape contract for this method (and any similar ones), or update downstream consumers to handle errors via try/catch consistently.

Copilot uses AI. Check for mistakes.
Comment on lines 204 to 207
const message = { ...data };
if (message.ts?.$date) {
console.log(message.ts?.$date);
message.ts = message.ts.$date;
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

There is a console.log in the message normalization path. This will spam logs in production for every message that has ts.$date and can leak data into client logs. Please remove it or route through the project’s structured/logger abstraction if one exists.

Copilot uses AI. Check for mistakes.
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.

Critical: handleTypingEvent busy-wait blocks main thread and freezes UI during typing updates

1 participant