Skip to content

fix(chat): drop malformed user content instead of throwing - #359

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/chat-malformed-user-content
Sep 5, 2026
Merged

fix(chat): drop malformed user content instead of throwing#359
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/chat-malformed-user-content

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

toVisibleChatItems assumed any non-string user content is an array and called .filter on it. Live turns bypass schema validation, so one malformed turn (undefined/null/number) threw TypeError inside render and unmounted the whole transcript.

Fix adds an Array.isArray guard returning [] for non-string non-array content, matching the existing unknown-role policy.

Repro: toVisibleChatItems([{id:"1",role:"user",content:undefined}]) threw before, returns [] after.

Tests: added malformed-content case to app/tests/chat-messages.test.ts (9 pass). Biome clean.

@davidmckayv davidmckayv 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.

Reviewed diff against current main; resolved CHANGELOG keep-both; validated locally (format + composed test run). CI green.

@davidmckayv
davidmckayv merged commit 54f937f into CopilotKit:main Sep 5, 2026
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.

2 participants