Skip to content

Use a 50ms default publication cadence for useChat in v8 #18547

Description

@gr2m

Background

#18525 fixed useChat throttling so a configured throttle limits the message snapshots published to React. Before that fix, throttling only delayed the subscription callback; unrelated React renders could still observe the latest chat.messages array for every stream chunk and bypass the configured cadence.

The fix intentionally preserved the current default: when throttle is omitted, message snapshots remain unthrottled. Applications therefore need to know that they should opt into throttling to avoid excessive React work during fast, high-frequency streams. This is particularly noticeable on slower devices or when rendering expensive content such as Markdown, tool calls, or context menus, as reported in #6166.

Changing the omitted default affects observable rendering behavior and is therefore appropriate for the next major release.

Goal (v8)

Use a 50ms publication cadence for useChat message snapshots when throttle is omitted, while preserving an explicit unthrottled opt-out:

throttle value Behavior
omitted Publish React message snapshots at a 50ms cadence
0 Publish every message snapshot without throttling
positive number Publish at the configured cadence

Stream processing, tool handling, and callbacks should remain immediate. Only snapshots exposed to React should be paced.

The default cadence must include an immediate leading publication and a terminal flush so the final messages are visible on the same render where ready or error becomes observable, including aborts that transition back to ready.

Tasks

  • Change the omitted useChat throttle default to 50ms in @ai-sdk/react.
  • Preserve throttle: 0 as the explicit unthrottled opt-out.
  • Add regression tests for omitted, zero, and custom throttle values.
  • Verify an immediate leading publication and terminal message/status coherence for normal completion, errors, and aborts.
  • Extend the deterministic browser reproduction from fix(react): throttle published useChat snapshots #18525 to cover both the new default and the explicit unthrottled opt-out.
  • Update the useChat API documentation and examples to describe the new default and opt-out.
  • Add a v7-to-v8 migration-guide entry explaining the rendering-semantics change.
  • Add a major changeset for @ai-sdk/react.
  • Decide whether equivalent UI hooks or framework integrations should adopt the same default for consistency.

Acceptance Criteria

  • Omitting throttle caps normal React message publications at approximately 20 updates per second.
  • throttle: 0 retains the existing per-update behavior.
  • Explicit positive values continue to control the publication cadence.
  • Stream consumption, callbacks, tool handling, and internal chat state are not delayed.
  • Final messages and terminal status remain coherent in the same render.
  • The behavior is covered by unit tests and a real browser reproduction.

Tradeoffs

The default protects applications that do not know they need to opt in today and provides a predictable upper bound on normal React rendering work. The cost is up to 50ms of additional visible text latency, fewer intermediate renders, and an explicit opt-out for applications that intentionally require per-chunk rendering.

References

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions