-
Notifications
You must be signed in to change notification settings - Fork 340
fix(api): remove typing busy-wait and harden API handling #1153
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
base: develop
Are you sure you want to change the base?
fix(api): remove typing busy-wait and harden API handling #1153
Conversation
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.
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
handleTypingEventbusy-wait/lock to prevent UI unresponsiveness. - Introduced
throwApiErrorand replaced manyconsole.*catch handlers with consistent error propagation. - Replaced deep-clone (
JSON.parse(JSON.stringify(...))) with shallow copies for incoming message objects and updatedchat.searchto useURLSearchParams.
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.
packages/api/src/EmbeddedChatApi.ts
Outdated
| } | ||
|
|
||
| private throwApiError(error: unknown): never { | ||
| if (error instanceof Error || error instanceof ApiError) { |
Copilot
AI
Feb 11, 2026
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.
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.
| if (error instanceof Error || error instanceof ApiError) { | |
| if (error instanceof Error) { |
| }); | ||
| return await response.json(); | ||
| } catch (err) { | ||
| return { | ||
| error: err, | ||
| }; | ||
| this.throwApiError(err); | ||
| } |
Copilot
AI
Feb 11, 2026
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.
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.
| const message = { ...data }; | ||
| if (message.ts?.$date) { | ||
| console.log(message.ts?.$date); | ||
| message.ts = message.ts.$date; |
Copilot
AI
Feb 11, 2026
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.
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.
fix(api): prevent typing update UI freeze and improve API robustness
Acceptance Criteria fulfillment
handleTypingEvent.throwApiError.JSON.parse(JSON.stringify(data))with shallow object copies in message processing.URLSearchParams.Fixes #1151
PR Test Details
yarn workspace @embeddedchat/api build(passed).typingHandlerLock/ busy-wait logic remains inEmbeddedChatApi.ts.chat.searchnow builds query strings usingURLSearchParams.