fix(composer): preserve in-progress message across reconnect soft-refresh (LC-346) #361
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/lc-346-composer-refresh-preserve"
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?
What
A WebSocket reconnect soft-refresh (LC-318) re-renders all of
#main, including the composer. The composer came back seeded from the server-side draft, but the draft autosave PUT is debounced on a 1s idle gap and resets on every keystroke, so it never settles during continuous typing. A long in-progress message was therefore discarded on every reconnect (the entire message when typing without a >1s pause), and on a flaky link the refresh fires repeatedly so the message could never be finished. Caret/focus, a staged-but-unsent attachment, and an active quote/reply bar were lost too.How
In
enterConnected()(server/templates/layout.html), snapshot the live composer immediately before the soft-refreshhtmx.ajax: textarea value, caret/selection, focus, hiddenfile_id, the#lc-stagedattachment chip, and the#composer-quote-barquote/reply chip (with its hiddenquote_id).htmx.ajaxreturns a Promise; in its.then(), once the fresh composer and its IIFEs are mounted, restore the snapshot onto the new nodes (value, caret viasetSelectionRange, focus,file_id, staged chip, quote bar), dispatch a syntheticinputso the resize/counter listeners re-measure, and callwindow.__lcRefreshSend()to recompute the Send-button state. When nothing was in progress, restore is skipped so the server-rendered LC-64 draft still stands.The capture/restore lives at the single soft-refresh site (the only path that replaces a mounted composer) rather than
hx-preserveon the composer, which would re-run the sibling composer<script>tags on the#mainswap and double-bind their document-level listeners, breaking the LC-156 "never accumulate duplicate listeners" invariant. DM and room composers share the same ids, so one snapshot covers both.Testing
JS-only edit inside an existing
<script>block; no Rust, migrations, cfg gates, or handler contracts changed.just check(server standalone + saas, desktop, clippy both modes, fmt),just test, andjust test-saasall green.#LC-346