Repository navigation
@tanstack/ai-react@0.31.0
Minor Changes
-
#1232
ef6c44f- Hold client UI state in a TanStack Store atom. Framework hooks readgetSnapshot()instead of copying fields through change callbacks. ReactuseChat()first commitsinitialMessagesandinitialResumeSnapshot, then applies browser persistence after attach. This timing applies to client-only rendering and keeps the server snapshot stable during SSR hydration. Until the stored transcript is applied,isHydratingistrue.The snapshot
messagesandqueuearrays are frozen in every adapter. An in-place change such asmessages.push()throws aTypeError. UsesetMessagesto change messages. The hook return types now show this:messagesandqueueareReadonlyArray, and so isRealtimeClientState.messages. If you passmessagesto your own component or function, type that parameter asReadonlyArray<UIMessage>.Snapshot message
partsare frozen at runtime too, but their TypeScript type stays mutable, because a readonly part list is not assignable toUIMessage. Toolinput,output, and subagent transcripts on a snapshot are copies.A message or part that did not change keeps the same object from one snapshot to the next. Memoized message rows do not render again when a different message streams.
ChatClientaddssubscribeSnapshot/getSnapshot. The live connection method stayssubscribe(). Generation, video, realtime, and BYOK clients exposesubscribe/getSnapshot.AudioRecorder.subscribestill passes the new state value.RealtimeClientbehavior changes: whenconnect()connects, it clears the messages and the pending user and assistant transcripts from the previous session. A transcript that arrives while the microphone starts is kept. A failed connection keeps the previous transcript.interrupt()now clearspendingAssistantTranscript.setMessagesaccepts the hook's readonlymessages, including nested subagent cards. A listener that throws does not skip the other listeners in any client, and it does not leaveisLoadingstuck. The error goes toreportErrorin the browser and toconsole.errorin other runtimes.