Throttle chat store updates to fix React #185 in SAM chat (#522)

This commit is contained in:
Ben Senescu 2026-08-26 09:38:33 -04:00 committed by GitHub
parent 044d712580
commit 7f9d73102e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -87,7 +87,12 @@ export function OnboardingChatConversation({
// in the Worker (src/server.ts) before it reaches the DO; billing gates come // in the Worker (src/server.ts) before it reaches the DO; billing gates come
// back as normal assistant messages rather than HTTP errors. // back as normal assistant messages rather than HTTP errors.
const agent = useAgent({ agent: "onboarding-chat", name: projectId }); const agent = useAgent({ agent: "onboarding-chat", name: projectId });
const { messages, sendMessage, status } = useAgentChat({ agent }); // Same constraint as SAM: dense tool-input deltas fan out one store update
// per chunk and trip React #185 unthrottled (cloudflare/agents#1361).
const { messages, sendMessage, status } = useAgentChat({
agent,
experimental_throttle: 50,
});
// This chat is only ever the pre-upgrade free preview: once a user upgrades // This chat is only ever the pre-upgrade free preview: once a user upgrades
// they are routed into the GSC onboarding step and never return here, so // they are routed into the GSC onboarding step and never return here, so

View File

@ -30,8 +30,10 @@ export function SamConversation({
// session id. The WebSocket is authorized in the Worker (src/server.ts) before // session id. The WebSocket is authorized in the Worker (src/server.ts) before
// it reaches the DO; billing gates come back as normal assistant messages. // it reaches the DO; billing gates come back as normal assistant messages.
const agent = useAgent({ agent: "sam-chat", name: sessionId }); const agent = useAgent({ agent: "sam-chat", name: sessionId });
// SAM streams dense tool-input deltas; unthrottled per-chunk store fanout
// re-renders the transcript per delta and trips React #185 (cloudflare/agents#1361).
const { messages, sendMessage, setMessages, clearHistory, status } = const { messages, sendMessage, setMessages, clearHistory, status } =
useAgentChat({ agent }); useAgentChat({ agent, experimental_throttle: 50 });
const isBusy = status === "submitted" || status === "streaming"; const isBusy = status === "submitted" || status === "streaming";
const { scrollRef, onScroll, pinToBottom } = useStickToBottom( const { scrollRef, onScroll, pinToBottom } = useStickToBottom(