Skip to content

ToolInput crashes the tree while tool input is streaming (input is undefined, CodeBlock calls code.split) #490

Description

@kalinichenko88

Components: tool.tsx (ToolInput), code-block.tsx (CodeBlockContent)

What happens

While a tool part is in input-streaming, part.input is undefined. ToolInput renders <CodeBlock code={JSON.stringify(input, null, 2)} /> (tool.tsx:125); JSON.stringify(undefined) returns undefined, and createRawTokens calls code.split("\n") on it (code-block.tsx:171, from the useMemo at :384):

TypeError: Cannot read properties of undefined (reading 'split')
  createRawTokens   src/components/ai-elements/code-block.tsx:171
  CodeBlockContent  src/components/ai-elements/code-block.tsx:384

React unmounts the tree, so the whole chat stops rendering, not just the tool card. The props type allows it: ToolPart["input"] is unknown.

Repro

Render a tool part in every state:

<Tool>
  <ToolHeader type="dynamic-tool" state={part.state} toolName={part.toolName} />
  <ToolContent>
    <ToolInput input={part.input} />
    <ToolOutput output={part.output} errorText={part.errorText} />
  </ToolContent>
</Tool>

and stream a tool call whose input arrives in deltas. Observed stream: tool-input-starttool-input-deltatool-input-available; the crash happens on the render between the first two.

Observed with @ai-sdk/langchain 3.0.99, ai 7.0.99, @ai-sdk/react 4.0.102, React 19.3.0, Vite 8.3.0, components added from the @ai-elements registry on 2026-09-13. The same code is on main today. The throw is in render code, so the framework should not matter.

Workaround

Render ToolInput only once the input exists: {part.input !== undefined && <ToolInput input={part.input} />}.

Possible fix

Return null (or a pending placeholder) from ToolInput when input === undefined, or make CodeBlock tolerate a non-string code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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