1 Commits

Author SHA1 Message Date
Ryan Hamamura
d6e64763cc fix: use templ.NewOnceHandle to prevent script duplication on SSE patches
All checks were successful
CI / Deploy / test (pull_request) Successful in 15s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
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.
2026-03-03 10:43:23 -10:00

View File

@@ -52,6 +52,8 @@ func isStale(lastPing int64) bool {
return lastPing == 0 return lastPing == 0
} }
var connectionWatcherHandle = templ.NewOnceHandle()
// ConnectionIndicator shows a small dot indicating SSE connection status. // ConnectionIndicator shows a small dot indicating SSE connection status.
// Server patches this with a timestamp; client JS detects staleness. // Server patches this with a timestamp; client JS detects staleness.
templ ConnectionIndicator(lastPing int64) { templ ConnectionIndicator(lastPing int64) {
@@ -79,7 +81,9 @@ templ ConnectionIndicator(lastPing int64) {
></div> ></div>
</div> </div>
</div> </div>
@connectionWatcher() @connectionWatcherHandle.Once() {
@connectionWatcher()
}
} }
script connectionWatcher() { script connectionWatcher() {