fix: separate connection indicator script from patchable element
The script was being re-added on every SSE patch, creating multiple setInterval timers. Split into ConnectionIndicator (for patches) and ConnectionIndicatorWithScript (for initial page render).
This commit is contained in:
@@ -54,6 +54,7 @@ func isStale(lastPing int64) bool {
|
||||
|
||||
// ConnectionIndicator shows a small dot indicating SSE connection status.
|
||||
// Server patches this with a timestamp; client JS detects staleness.
|
||||
// Use ConnectionIndicatorWithScript for initial render, ConnectionIndicator for patches.
|
||||
templ ConnectionIndicator(lastPing int64) {
|
||||
<div
|
||||
id="connection-indicator"
|
||||
@@ -79,6 +80,12 @@ templ ConnectionIndicator(lastPing int64) {
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
// ConnectionIndicatorWithScript renders the indicator with the staleness watcher script.
|
||||
// Use this for initial page render only.
|
||||
templ ConnectionIndicatorWithScript(lastPing int64) {
|
||||
@ConnectionIndicator(lastPing)
|
||||
@connectionWatcher()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user