From e535a0181eeef12cd1f6eb8ee28e7462a1cda047 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 27 Apr 2026 14:30:07 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20load=20htmx-1.x=20SSE=20ext=20(was=202.x?= =?UTF-8?q?=20=E2=80=94=20incompatible)=20+=20Enter-to-send?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - htmx-ext-sse@2.2.2 is for htmx 2.x; with htmx 1.9.12 the extension registers but the SSE attributes silently no-op (different ext API generation). The 1.x SSE extension is bundled with htmx itself at unpkg.com/htmx.org@1.9.12/dist/ext/sse.js — point at that. - Enter submits the turn-input form (Shift+Enter for newline). Uses form.requestSubmit() so the existing submit listener (optimistic user-prose render + fetch + textarea clear) handles both keyboard and click submissions identically. --- chat/templates/base.html | 5 ++++- chat/templates/chat.html | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/chat/templates/base.html b/chat/templates/base.html index 916d779..2e6e7e3 100644 --- a/chat/templates/base.html +++ b/chat/templates/base.html @@ -6,7 +6,10 @@ {% block title %}chat{% endblock %} - + + {% block body %}{% endblock %} diff --git a/chat/templates/chat.html b/chat/templates/chat.html index 7f16c65..5b1453f 100644 --- a/chat/templates/chat.html +++ b/chat/templates/chat.html @@ -162,6 +162,22 @@ document.querySelector('.drawer-toggle')?.addEventListener('click', (e) => { } }); + // Enter-to-send (Shift+Enter for newline). Submits via the form's + // own submit event so all the optimistic-render + fetch logic + // below applies uniformly to keyboard and click submissions. + if (textarea) { + textarea.addEventListener('keydown', (e) => { + if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { + e.preventDefault(); + if (typeof form.requestSubmit === 'function') { + form.requestSubmit(); + } else { + form.dispatchEvent(new Event('submit', { cancelable: true })); + } + } + }); + } + // Render the user's prose optimistically as a turn-you DOM node. // Without this the user can't see what they just sent until the page // reloads — the server persists ``user_turn`` events but doesn't