Skip to content

Commit b219492

Browse files
committed
fix(chat): keep the caret where the user typed before hydration
1 parent 2e86d2d commit b219492

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/home/components/user-input

‎apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(function UserI
203203
}
204204
if (restoredContexts) editor.setContexts(restoredContexts)
205205
if (restoredFiles) files.restoreAttachedFiles(restoredFiles)
206-
if (caretText !== null) {
207-
if (editor.getValue() === '') editor.setValue(caretText, { seed: true })
206+
// Text typed before hydration wins over the saved draft, caret included.
207+
const typedBeforeHydration = initialValue === '' && editor.getValue() !== ''
208+
if (caretText !== null && !typedBeforeHydration) {
209+
if (initialValue === '') editor.setValue(caretText, { seed: true })
208210
const textarea = textareaRef.current
209211
if (textarea) {
210212
if (!isMobileViewport()) textarea.focus()

0 commit comments

Comments
 (0)