fix: append chat messages instead of re-rendering entire game
All checks were successful
CI / Deploy / test (push) Successful in 15s
CI / Deploy / lint (push) Successful in 25s
CI / Deploy / deploy (push) Successful in 33s

Previously patchAll() re-rendered the full GameContent on every chat
message, which was inefficient and could cause UI glitches. Now we
append just the new ChatMessage to the chat history element.
This commit is contained in:
Ryan Hamamura
2026-03-03 09:09:51 -10:00
parent ac2492e7c1
commit 6976b773bd
3 changed files with 26 additions and 11 deletions

View File

@@ -148,8 +148,13 @@ func HandleGameEvents(store *connect4.Store, nc *nats.Conn, sm *scs.SessionManag
return
}
case msg := <-chatCh:
room.Receive(msg.Data)
if err := patchAll(); err != nil {
chatMsg, _ := room.Receive(msg.Data)
err := sse.PatchElementTempl(
chatcomponents.ChatMessage(chatMsg, chatCfg),
datastar.WithSelectorID("c4-chat-history"),
datastar.WithModeAppend(),
)
if err != nil {
return
}
}

View File

@@ -172,8 +172,13 @@ func HandleSnakeEvents(snakeStore *snake.SnakeStore, nc *nats.Conn, sm *scs.Sess
if msg == nil {
continue
}
room.Receive(msg.Data)
if err := patchAll(); err != nil {
chatMsg, _ := room.Receive(msg.Data)
err := sse.PatchElementTempl(
chatcomponents.ChatMessage(chatMsg, chatCfg),
datastar.WithSelectorID("snake-chat-history"),
datastar.WithModeAppend(),
)
if err != nil {
return
}
}