You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
react: add TransportProvider, make useClientTransport a context reader
Previously, useClientTransport was a factory hook: callers were
responsible for obtaining a channel via useChannel, passing it along
with codec and other options, and threading the resulting transport
instance through props to every consumer component.
This change introduces TransportProvider<TEvent, TMessage>, which
centralises channel setup and transport creation. The provider wraps
ChannelProvider internally, co-locates channel and transport lifecycle,
and registers the transport in a React context.
useClientTransport is now a thin context reader.
- src/react/contexts/transport-context.ts: new context (Record-based)
- src/react/contexts/transport-provider.tsx: new provider, two-component
pattern so useChannel is called inside ChannelProvider's subtree
- src/react/use-client-transport.ts: rewritten as context reader
- Both demos updated to wrap at page level with TransportProvider
- All docs updated to the new API
- Tests rewritten: transport-provider.test.ts (new, 8 tests),
use-client-transport.test.ts (context-based, no transport creation)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/frameworks/vercel-ai-sdk.md
+25-7Lines changed: 25 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,13 +19,20 @@ The Vercel AI SDK provides model abstraction, streaming primitives, and React ho
19
19
20
20
Wrap the transport in a `ChatTransport` adapter and pass it to Vercel's `useChat()`. Message state is managed by `useChat()` - the transport delivers messages over Ably instead of HTTP.
`useChatTransport()` wraps the core transport into the `ChatTransport` interface that `useChat()` expects. `useMessageSync()` pushes the transport's authoritative message list into `useChat()`'s state - this is how messages from other clients appear.
47
+
`TransportProvider` creates the transport and wraps children with `ChannelProvider` internally. `useClientTransport()` reads it from context. `useChatTransport()` wraps the core transport into the `ChatTransport` interface that `useChat()` expects. `useMessageSync()` pushes the transport's authoritative message list into `useChat()`'s state - this is how messages from other clients appear.
41
48
42
49
### Generic hooks path (more control)
43
50
44
51
Use the generic React hooks directly. You manage message state through the transport's conversation tree instead of `useChat()`.
0 commit comments