From 1034efcec49cd82bb1ec0083528ced2fbac0ddbd Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Sat, 16 May 2026 10:29:38 +0200 Subject: [PATCH] fix(12-03): clear discussion composer after suppressed swap --- backend/internal/web/handlers_discussion_test.go | 2 +- backend/static/discussion-sse.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/internal/web/handlers_discussion_test.go b/backend/internal/web/handlers_discussion_test.go index 7b57fc5..f74cbd2 100644 --- a/backend/internal/web/handlers_discussion_test.go +++ b/backend/internal/web/handlers_discussion_test.go @@ -491,7 +491,7 @@ func TestDiscussionStaticScriptClearsComposerAfterSuccessfulPost(t *testing.T) { t.Fatalf("read discussion-sse.js: %v", err) } script := string(js) - for _, want := range []string{"htmx:afterRequest", "requestConfig.elt", "discussion-message-body", ".reset()"} { + for _, want := range []string{"htmx:afterRequest", "requestConfig.elt", "isSuccessfulDiscussionPost", "xhr.status", "discussion-message-body", ".reset()"} { if !strings.Contains(script, want) { t.Fatalf("discussion script missing %q for composer reset; script: %.1200s", want, script) } diff --git a/backend/static/discussion-sse.js b/backend/static/discussion-sse.js index 8d198a3..6c8059b 100644 --- a/backend/static/discussion-sse.js +++ b/backend/static/discussion-sse.js @@ -11,6 +11,11 @@ return detail && detail.requestConfig && detail.requestConfig.elt; } + function isSuccessfulDiscussionPost(detail) { + var status = detail && detail.xhr && detail.xhr.status; + return status >= 200 && status < 300; + } + function messageIdFromHTML(html) { if (!html) return ""; var template = document.createElement("template"); @@ -79,7 +84,7 @@ }); document.body.addEventListener("htmx:afterRequest", function (event) { var form = requestElement(event.detail); - if (!isDiscussionMessageForm(form) || !event.detail.successful) return; + if (!isDiscussionMessageForm(form) || !isSuccessfulDiscussionPost(event.detail)) return; form.reset(); var textarea = form.querySelector("#discussion-message-body");