Skip to content

fix(reasoning): keep the measured duration in plain state - #499

Open
RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix/reasoning-duration-controlled-warning
Open

RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix/reasoning-duration-controlled-warning

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes #496

Reasoning stored duration in useControllableState. A caller that passes duration={undefined} while streaming and a number once reasoning finishes switches the hook from uncontrolled to controlled. React logs this warning in development for every finished reasoning block:

undefined is changing from uncontrolled to controlled. Components should not switch from controlled to uncontrolled (or vice versa).

duration has no change callback, so the controllable-state hook adds nothing. This change keeps the measured duration in useState and uses durationProp ?? measuredDuration. The displayed value is the same in both modes: the prop when it is defined, otherwise the internal timer.

Tests

  • does not warn when duration is set after streaming ends renders with duration={undefined} and isStreaming, then rerenders with duration={3}. It fails before the change and passes after.
  • prefers the duration prop over the measured duration checks that a prop value wins over the timer.
cd packages/elements
npx vitest run __tests__/reasoning.test.tsx

Before the change: 2 failed, 18 passed. After: 20 passed. The full packages/elements suite passes (47 files, 960 tests).

useControllableState warns when the duration prop goes from undefined while streaming to a number once reasoning finishes. duration has no change callback, so the prop now takes precedence over the internal timer without the controlled/uncontrolled switch.
@vercel

vercel Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@RaphaelFakhri is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reasoning: passing duration once streaming ends logs "changing from uncontrolled to controlled"

1 participant