fix(composer): do not wipe in-progress text on draft-autosave (LC-338) #354
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/lc-338-composer-draft-wipe"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Typing a message in a room and pausing (or clicking off the input) wipes the in-progress text from the composer; a page refresh restores it. Reported on staging and latest main.
Root cause
The composer textarea auto-saves drafts:
server/templates/room/composer.html:217-263putshx-put="/room/{id}/draft"+hx-trigger="keyup[...] changed delay:1000ms"on<textarea name="body">, which lives inside the#composerform. That draft-save request bubbles up to the form'shx-on::after-requesthandler. The siblinghx-on::config-requesthandler guardsif (event.detail.elt !== this) return;(and documents skipping the draft-autosave PUT), butafter-requesthad no such guard. So ~1s after the user stops typing, the draft-save returns 204, the send-completion path runs,ta.value === sentBodyis true, andta.value = ''wipes the text. The draft is persisted server-side (LC-239), which is why a refresh restores it.No server-driven update touches the composer (send is 204 /
hx-swap="none"; WS fragments swap only#messages,#typing, and the sidebar draft badge). The defect is purely the missing client-side guard.Fix
Add the same
if (event.detail.elt !== this) return;guard tohx-on::after-request, scoping the entire send-completion body to the form's own send. Form send haselt === #composer; the bubbled draft-save haselt === <textarea> !== thisand is skipped. Bonus: a draft-save failure no longer incorrectly raises the composer send-error banner. Draft persistence is unchanged.Test
cargo check,just test,just test-saaspass (template-only change; no server logic touched).Closes LC-338.