fix: load htmx-1.x SSE ext (was 2.x — incompatible) + Enter-to-send
- 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.
This commit is contained in:
@@ -6,7 +6,10 @@
|
||||
<title>{% block title %}chat{% endblock %}</title>
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
<script src="https://unpkg.com/htmx.org@1.9.12" defer></script>
|
||||
<script src="https://unpkg.com/htmx-ext-sse@2.2.2/sse.js" defer></script>
|
||||
<!-- htmx 1.x bundles its SSE extension at /dist/ext/sse.js. The
|
||||
standalone htmx-ext-sse@2.x package is for htmx 2.x and is
|
||||
not compatible with the 1.x ext API. -->
|
||||
<script src="https://unpkg.com/htmx.org@1.9.12/dist/ext/sse.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
{% block body %}{% endblock %}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user