Skip to content

Unsafe user message content parsing causes React transcript crashes #44

Description

@arpan7sarkar

Description

In app/src/components/channels/chat-messages.ts, the toVisibleChatItems function assumes that any non-string message.content is an array of InputContent objects and calls .filter() directly:

const text =
 typeof message.content === "string"
   ? message.content
   : message.content
       .filter((part) => part.type === "text")
       .map((part) => part.text)
       .join("\n");

If message.content is undefined, null, or an unexpected object format (e.g. from partial streaming events, custom assistant/system payloads, or deserialized messages), calling .filter() throws an unhandled TypeError: Cannot read
properties of undefined (reading 'filter').

This crashes the React component tree and blanks the chat transcript for the user.

Steps to Reproduce

  1. Receive or restore a user message where content is undefined, null, or non-array.
  2. Render ChatTranscript or call toVisibleChatItems([message]).
  3. The component throws an unhandled TypeError during render.

Expected Behavior

toVisibleChatItems should safely handle non-array and malformed message.content values without throwing, falling back to an empty string.

Proposed Solution

  1. Add an Array.isArray(message.content) check before attempting to filter content parts.
  2. Ensure array elements are validated as { type: "text", text: string } objects before accessing .text.
  3. Add unit test coverage in app/tests/chat-messages.test.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions