Skip to content

handleSubmit called 2 times when pressing Enter during loading (interrupt) #11

@izuannazrin

Description

@izuannazrin

When the chat is loading (isGenerating=true), and you press Enter, the chat shows an interrupt prompt as intended. But when you press Enter again to interrupt, it does stop but it then causes onSubmit event two times.

The issue is inside message-input.tsx, in onKeyDown(), requestSubmit is called multiple times, first inside if statement and second outside.

const onKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
    if (submitOnEnter && event.key === "Enter" && !event.shiftKey) {
      event.preventDefault()

      if (isGenerating && stop && enableInterrupt) {
        if (showInterruptPrompt) {
          stop()
          setShowInterruptPrompt(false)
          event.currentTarget.form?.requestSubmit()  // <---- this one
        } else if (
          props.value ||
          (props.allowAttachments && props.files?.length)
        ) {
          setShowInterruptPrompt(true)
          return
        }
      }

      event.currentTarget.form?.requestSubmit()  // <---- or this one
    }

    onKeyDownProp?.(event)
  }

The fix is perhaps to remove the requestSubmit call inside the if statement, so submission is triggered by default, I guess.

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