Skip to content

Open source alternative to Semrush and Ahrefs

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

Ben Senescu7f9d73102e9f
diff --git a/src/client/features/onboarding/OnboardingChatConversation.tsx b/src/client/features/onboarding/OnboardingChatConversation.tsx
index f7b52a63..04eb04f1 100644
--- a/src/client/features/onboarding/OnboardingChatConversation.tsx
+++ b/src/client/features/onboarding/OnboardingChatConversation.tsx
@@ -87,7 +87,12 @@ export function OnboardingChatConversation({
// in the Worker (src/server.ts) before it reaches the DO; billing gates come
// back as normal assistant messages rather than HTTP errors.
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
// they are routed into the GSC onboarding step and never return here, so
diff --git a/src/client/features/sam/SamConversation.tsx b/src/client/features/sam/SamConversation.tsx
index 4a808228..27408454 100644
--- a/src/client/features/sam/SamConversation.tsx
+++ b/src/client/features/sam/SamConversation.tsx
@@ -30,8 +30,10 @@ export function SamConversation({
// 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.
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 } =
- useAgentChat({ agent });
+ useAgentChat({ agent, experimental_throttle: 50 });
const isBusy = status === "submitted" || status === "streaming";
const { scrollRef, onScroll, pinToBottom } = useStickToBottom(