1 Commits

Author SHA1 Message Date
Ryan Hamamura
0e344de9c1 fix: separate connection indicator script from patchable element
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
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).
2026-03-03 10:39:26 -10:00
3 changed files with 9 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ templ GamePage(g *connect4.Game, myColor int, messages []chat.Message, chatCfg c
data-signals="{chatMsg: ''}"
data-init={ fmt.Sprintf("@get('/games/%s/events',{requestCancellation:'disabled'})", g.ID) }
>
@sharedcomponents.ConnectionIndicator(0)
@sharedcomponents.ConnectionIndicatorWithScript(0)
@GameContent(g, myColor, messages, chatCfg)
</main>
}

View File

@@ -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()
}

View File

@@ -37,7 +37,7 @@ templ GamePage(sg *snake.SnakeGame, mySlot int, messages []chat.Message, chatCfg
data-on:keydown__throttle.100ms={ keydownScript(gameID) }
tabindex="0"
>
@components.ConnectionIndicator(0)
@components.ConnectionIndicatorWithScript(0)
@GameContent(sg, mySlot, messages, chatCfg, gameID)
</main>
}