Fix SSE live updates being cancelled on user interaction #6

Merged
ryan merged 1 commits from fix/sse-request-cancellation into main 2026-03-03 18:52:06 +00:00
2 changed files with 4 additions and 3 deletions

View File

@@ -1,13 +1,14 @@
package pages package pages
import ( import (
"fmt"
"github.com/ryanhamamura/games/chat" "github.com/ryanhamamura/games/chat"
chatcomponents "github.com/ryanhamamura/games/chat/components" chatcomponents "github.com/ryanhamamura/games/chat/components"
"github.com/ryanhamamura/games/connect4" "github.com/ryanhamamura/games/connect4"
"github.com/ryanhamamura/games/features/c4game/components" "github.com/ryanhamamura/games/features/c4game/components"
sharedcomponents "github.com/ryanhamamura/games/features/common/components" sharedcomponents "github.com/ryanhamamura/games/features/common/components"
"github.com/ryanhamamura/games/features/common/layouts" "github.com/ryanhamamura/games/features/common/layouts"
"github.com/starfederation/datastar-go/datastar"
) )
templ GamePage(g *connect4.Game, myColor int, messages []chat.Message, chatCfg chatcomponents.Config) { templ GamePage(g *connect4.Game, myColor int, messages []chat.Message, chatCfg chatcomponents.Config) {
@@ -15,7 +16,7 @@ templ GamePage(g *connect4.Game, myColor int, messages []chat.Message, chatCfg c
<main <main
class="flex flex-col items-center gap-4 p-4" class="flex flex-col items-center gap-4 p-4"
data-signals="{chatMsg: ''}" data-signals="{chatMsg: ''}"
data-init={ datastar.GetSSE("/games/%s/events", g.ID) } data-init={ fmt.Sprintf("@get('/games/%s/events',{requestCancellation:'disabled'})", g.ID) }
> >
@GameContent(g, myColor, messages, chatCfg) @GameContent(g, myColor, messages, chatCfg)
</main> </main>

View File

@@ -33,7 +33,7 @@ templ GamePage(sg *snake.SnakeGame, mySlot int, messages []chat.Message, chatCfg
<main <main
class="snake-wrapper flex flex-col items-center gap-4 p-4" class="snake-wrapper flex flex-col items-center gap-4 p-4"
data-signals={ `{"chatMsg":""}` } data-signals={ `{"chatMsg":""}` }
data-init={ datastar.GetSSE("/snake/%s/events", gameID) } data-init={ fmt.Sprintf("@get('/snake/%s/events',{requestCancellation:'disabled'})", gameID) }
data-on:keydown__throttle.100ms={ keydownScript(gameID) } data-on:keydown__throttle.100ms={ keydownScript(gameID) }
tabindex="0" tabindex="0"
> >