From d6e64763cc4e0b767dabc86522ec440269986968 Mon Sep 17 00:00:00 2001 From: Ryan Hamamura <58859899+ryanhamamura@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:39:26 -1000 Subject: [PATCH] fix: use templ.NewOnceHandle to prevent script duplication on SSE patches Replace ConnectionIndicatorWithScript wrapper with a single ConnectionIndicator component that uses templ.NewOnceHandle() to ensure the watcher script is only rendered once per page, even when the indicator is patched via SSE. --- features/common/components/shared.templ | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/features/common/components/shared.templ b/features/common/components/shared.templ index a9b783b..d5f68c0 100644 --- a/features/common/components/shared.templ +++ b/features/common/components/shared.templ @@ -52,6 +52,8 @@ func isStale(lastPing int64) bool { return lastPing == 0 } +var connectionWatcherHandle = templ.NewOnceHandle() + // ConnectionIndicator shows a small dot indicating SSE connection status. // Server patches this with a timestamp; client JS detects staleness. templ ConnectionIndicator(lastPing int64) { @@ -79,7 +81,9 @@ templ ConnectionIndicator(lastPing int64) { > - @connectionWatcher() + @connectionWatcherHandle.Once() { + @connectionWatcher() + } } script connectionWatcher() {