fix(web): note save was re-rendering the editor, causing content to duplicate#11
Merged
SwathiMystery merged 1 commit intomainfrom Apr 21, 2026
Merged
Conversation
…uplicate
Root cause
- POST /notes/{trade|day}/... returned the entire note_block partial,
and the form's hx-swap="outerHTML" replaced #note-block wholesale.
- EasyMDE's CodeMirror DOM sat *inside* #note-block. When the block
was swapped, the old CodeMirror stayed attached to the detached
textarea while a new one mounted on the fresh textarea. The
htmx:afterSwap listener that re-wired the editor was registered
inside wire() — one listener per mount — so every save added
another listener and every listener re-mounted. Content visually
duplicated because multiple CodeMirrors stacked on top of each
other all flushed into the same hidden textarea.
Fix
- Save endpoint now returns just partials/note_meta.html — a single
<span id="note-meta-stamp"> with the saved-at timestamp. 78 bytes
per save versus ~1.5 KB of editor HTML.
- Form's hx-target narrowed to #note-meta-stamp, hx-swap="outerHTML"
replaces only that span. Editor DOM untouched.
- editor.js: CodeMirror 'blur' now fires htmx.trigger(form,
'khata-save') — autosave without touching the editor DOM.
- Removed the htmx:afterSwap re-mount listener (no longer needed;
nothing swaps the editor).
- Tests updated to assert the stamp-only response, then verify
persistence via a follow-up GET.
No schema change. 46/46 tests green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Every save of a daily or trade note appeared to duplicate the textarea content. Hitting save a second time duplicated again.
Root cause
Fix
Verification
Checklist