commit de9c24459a1e2f9d348f3bb56270473444b27f52
parent d4a353f8d326e863fede66c19b068dbe222bce18
Author: Silas Brack <silasbrack@gmail.com>
Date: Thu, 11 Jun 2026 15:24:33 +0200
fix: use data-init instead of data-on:load for SSE connection
data-on:load only fires the native DOM load event, which doesn't
fire on <section> elements. Datastar's data-init is the correct
way to run expressions (including @get) when an element is first
processed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/handlers/story.rs b/src/handlers/story.rs
@@ -384,7 +384,7 @@ fn render_comments_event(
let inner_html = template.render().ok()?;
let html = format!(
"<section class=\"comments\" id=\"comments-section\" \
- data-on:load=\"@get('/story/{story_id}/comments-stream', \
+ data-init=\"@get('/story/{story_id}/comments-stream', \
{{requestCancellation: 'cleanup'}})\">\
{inner_html}</section>"
);
diff --git a/templates/story.html b/templates/story.html
@@ -81,7 +81,7 @@
{% endif %}
<section class="comments" id="comments-section"
- data-on:load="@get('/story/{{ story.id }}/comments-stream', {requestCancellation: 'cleanup'})">
+ data-init="@get('/story/{{ story.id }}/comments-stream', {requestCancellation: 'cleanup'})">
{% include "comments.html" %}
</section>
</div>