Enter key submits form during streaming because querySelector('button[type="submit"]') returns null

Open Beginner friendly
#439 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
frontend

Research direction

Start in PromptInputTextarea and trace the Enter-key guard that queries the form for button[type="submit"], alongside PromptInputSubmit's generating/streaming state. Verify the behavior when no submit button is present, then reproduce the streaming scenario and confirm Enter no longer calls form.requestSubmit() mid-stream.

Written by the indexing model from the issue text.

Description

Bug

When PromptInputSubmit is in the generating/streaming state it renders with
type="button" instead of type="submit" to act as a stop button. This means
form.querySelector('button[type="submit"]') in PromptInputTextarea returns
null.

The Enter key guard checks submitButton?.disabled, which evaluates to
undefined when submitButton is null — so the guard never fires and
form.requestSubmit() is called anyway, allowing users to submit a new message
while the model is still streaming.

Fix

// before
if (submitButton?.disabled) {

// after
if (!submitButton || submitButton.disabled) {
No submit button in the DOM → we're in stop/generating mode → block submission.

Steps to reproduce

  1. Send a message and wait for the model to start streaming
  2. Type anything in the textarea and press Enter
  3. The form submits mid-stream
Dominant language
TypeScript
Stars
2.4k
Forks
283
Avg merge
32m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/ai-elements

All issues in vercel/ai-elements

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.