[BUG] Text duplication on paste and "ghost text" remnant after chat submission (Self-Hosted Docker)
Bug Description
When interacting with the main chat input field, I am experiencing two related UI/state-sync bugs:
- Double Paste: Pasting text into the input field (via Cmd+V or the right-click context menu) inserts the clipboard content twice.
- Ghost Text Remnant: After pressing Enter to submit the prompt, the API request goes through successfully and the AI begins responding, but a visual remnant of the submitted text remains stuck in the input box instead of clearing.
Deployment Type
- [ ] SurfSense Cloud (hosted version)
- [x] Self-hosted version
Steps to Reproduce
- Navigate to a new or existing chat (e.g.,
http://localhost:3929/dashboard/[id]/new-chat). - Copy any string of text to the clipboard.
- Paste the text into the chat input box -> Observe the text is duplicated.
- Press Enter to submit the message -> Observe the message sends, but the text remains visually stuck in the input field.
Expected Behavior
- Pasting should insert the clipboard content exactly once.
- Submitting the chat form should completely clear the input field's visual and internal state.
Actual Behavior
When pasting via keyboard shortcut or context menu, the clipboard string is inserted twice into the rich-text input area. Furthermore, upon pressing Enter, the network request to the backend successfully fires and the AI generates a response, but the DOM/input state fails to clear, leaving the previously submitted text visually stuck in the chat box as "ghost text".
Environment Information
- Browser: Safari 26.5.2 (21624.2.5.11.8) and Chrome 150.0.7871.129 (arm64)
- Operating System: macOS (Apple Silicon M2 Pro)
- SurfSense Version: 0.0.34
Additional Environment Details (for Self-hosted only)
- Python Version: 3.12.13
- Node.js Version: v20.20.2
- Database: PostgreSQL 17 (
pgvector/pgvector:pg17) - Deployment Method: Docker Compose (via official
docker-compose.yml)
Additional Context
I have already performed extensive troubleshooting to isolate this issue and confirm it is a core frontend code bug, not a local environment glitch:
- Tested in Incognito/Private Windows: To completely rule out browser extensions (like Grammarly, clipboard managers, etc.). The bug still occurs.
- Cleared Cache & Storage: Cleared browser cache, LocalStorage, and unregistered Service Workers to ensure the absolute newest frontend assets were loaded.
- Cross-Browser Testing: Reproduced on both Chromium-based browsers (Chrome) and WebKit (Safari).
Suspected Technical Root Cause (Jotai State Desync):
Checking the browser console reveals a critical warning: Detected multiple Jotai instances. It may cause unexpected behavior with the default store.
Because SurfSense uses Jotai for React state management, loading duplicate instances of the library causes the chat input's state to desync. This explains why the UI fails to clear the text box upon submission (one instance clears, the other retains the DOM state) and why paste events are duplicating (race conditions between the split stores and native browser events). This is likely a Webpack/bundling issue in the surfsense-web Docker image where Jotai is being bundled into a shared component library as well as the main app.
Logs/Error Messages
0fd38ba2f10381f4.js:5 Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044
88184a3b3a5f6ad0.js:6 Tooltip is changing from controlled to uncontrolled. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.
0317e851df8fc883.js:1 Error: <circle> attribute r: Expected length, "undefined".
# Checklist
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I have provided all the required information above
- [x] I have added appropriate labels (bug, deployment type)
I tried to reproduce both symptoms on the current dev branch (17454fd8, 2026-09-08) with
a self-hosted setup and could not, and I think the paste half was fixed shortly after this
report.
Double paste. At 0.0.34 the chat composer (surfsense_web/components/assistant-ui/inline-mention-editor.tsx)
had a custom onPaste handler that called insertText itself on top of the editor's own
paste handling. Commit 7ecf01f30 (2026-07-22, "refactor: remove onPaste handler from
InlineMentionEditor for cleaner code") removed it. That commit is in 0.0.35.1 and every
later release. On dev, one Cmd+V inserts the clipboard text exactly once.
Ghost text after Enter. Also not reproducible on dev: after submit, the composer
contains only its placeholder ("Ask anything, use / or @"), and the submitted text shows
once in the thread. The submit path clears the Plate editor through setValue, which goes
through Slate operations, so the DOM follows.
How I checked: the repo's Playwright harness (surfsense_web/tests/README.md), a spec
that writes a unique marker to the clipboard, presses Cmd+V in the composer, counts the
marker in the editor text (expects 1), presses Enter, waits for the user turn, then asserts
the editor holds nothing but its placeholder. Result: 2 passed. Chromium on macOS arm64.
About the "Detected multiple Jotai instances" warning: the lockfile resolves jotai 2.18.0
for the app and 2.8.4 for @platejs/core, which pins jotai ~2.8.4. So the warning comes
from Plate's own dependency, not from the app's bundling, and it is still there on dev.
It does not appear to be involved in either symptom above.
@Beyond3345, could you retest on 0.0.35.1 or later? If both symptoms are gone for you as well, this issue can probably be closed.