Expose an isHydrating state from useChat
#1120
Visualizeit
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
When using server-authoritative persistence:
useChathydrates the conversation asynchronously on mount.While hydration is pending, the observable state is currently indistinguishable from an empty, ready conversation:
There is no public hydration state or lifecycle callback.
This makes it difficult to distinguish between:
Applications may consequently enable sending before the server-authoritative transcript, pending interrupts, or active run has been restored.
Using
messages.length === 0is unreliable because an empty conversation is valid. Wrappingconnection.hydrate()adds application glue and only observes the transport promise, not whenChatClienthas finished applying the result.Proposal
Expose
isHydratingfromChatClientand framework hooks:Suggested semantics:
truewhile initial asynchronous persistence hydration is running.falseafter the result has been applied.falsewhen hydration fails or is superseded by a new send.falseon the first observable render.isLoading,status, andsessionGenerating.This would let applications make their own UX decision:
Why a separate state?
isLoadingrepresents a request initiated or rejoined by the client.sessionGeneratingrepresents shared generation activity.isHydratingwould represent restoration of persisted client state.These lifecycles are related but not equivalent.
Current behavior
The current implementation treats server hydration as private, best-effort, and non-blocking. A new send can supersede it. That behavior is reasonable, but applications need visibility into the lifecycle to implement reliable input and loading states.
Relevant documentation:
useChatAPIAll reactions