[Bug] user prompt submits twice in new-ui redesign
Description
When submitting a message in the TUI, the prompt is duplicated and sent twice upon the first submission. Note: This issue only exists in our feature/new-ui branch because we are actively redesigning Nanocoder's UI and handling inputs more responsively in this branch. Please ensure any fixes are targeted strictly at feature/new-ui and not main.
Environment
- OS: Ubuntu (WSL)
- Node version: v22.20.0
- Nanocoder version: (latest
feature/new-uibranch) - Provider: Any
- Model: Any
Steps to Reproduce
- Switch to the
feature/new-uibranch and start the application (pnpm run start). - Type a message into the chat input box (e.g., "hi").
- Press
Enterto submit.
Expected Behavior
The prompt should appear once in the chat queue, and the application should send a single API request to the LLM.
Actual Behavior
The user's input bubble is printed twice into the chat history, and the system attempts to process the prompt concurrently due to rapid duplicate keystroke events bypassing the React isBusy lock.
Logs/Screenshots
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
Hi i was working on that issue and have implemented a fix. i will open a PR shortly
Dug into this, found the exact mechanism by driving real keystrokes against UserInput with ink-testing-library.
Root cause: handleSubmit (source/components/user-input.tsx:444-517) closes over currentState from its own render. resetInput() only clears the composer on the next render, so a second Enter landing before that commit still sees the old text and resubmits it.
Timed sweep of the gap between two Enters: [sync/1ms/5ms] onSubmit calls = ["msg", "msg"] [16ms] onSubmit calls = ["msg"]
Below ~16ms it double-fires. Also happens while busy, a double Enter queues the same message twice. No dedupe exists downstream either.
Fix: add a submittingRef latch set before onSubmit and cleared only once state confirms the reset, and read the input via a ref instead of the closed-over render state.
Happy to open a PR if useful.
- https://github.com/Nano-Collective/nanocoder/issues/1174
- https://github.com/Nano-Collective/nanocoder/issues/1167
Duplicates it seems, do we have a github action to auto de-dupe?
Correcting my earlier comment: @coralsundy is right about #1174, but #1167 is a different bug.
#1111 looks like the same bug as #1174. One Enter is enough. While the model hasn't streamed a token yet, the submitted prompt renders live (recallableSubmittedDraft, interactive-app.tsx:186). When the first chunk arrives it moves into <Static>, and in inline mode Ink prints it again into scrollback. It's one request, but the prompt shows twice. #1164 changes exactly this split, not submission.
The double-Enter race I described is real but needs two Enters within ~16ms, so it isn't the cause here. Happy to file it separately.
#1167 is unrelated: it's caused by terminal resize and traces to Ink's line-erase miscount (ink#907).
Also: feature/new-ui is now merged into main (#1261), and #1164 (base feature/new-ui) and #1182 (base main) both change the same code. It's probably worth picking one and closing this as a duplicate of #1174.
Fixed by #1182, which stopped the prompt being rendered twice when it moves into scrollback.
Closing as part of a backlog tidy-up. Reopen it if anything here is still broken.