Skip to content

Conversation

@agcty
Copy link
Contributor

@agcty agcty commented Dec 9, 2025

Summary

Update the React peer dependency from "*" (any version) to "^19.0.0".

Problem

The React hooks (useAgent, useAgentChat) use the use() hook:

// react.tsx:296
const queryResult = use(queryPromise!);

// ai-react.tsx:202
const initialMessages = initialMessagesPromise
  ? use(initialMessagesPromise)
  : (optionsInitialMessages ?? []);

The use() hook was introduced in React 19 and doesn't exist in React 18 or earlier. The current "react": "*" constraint is misleading since consumers on React 18 will get a confusing runtime error:

TypeError: use is not a function

Solution

Change "react": "*" to "react": "^19.0.0" in both peerDependencies and devDependencies. This makes the requirement explicit so consumers get a clear error during installation rather than at runtime.

Breaking Changes

Consumers on React 18 will now see a peer dependency warning/error during installation. However, the code was already broken for them at runtime, so this just surfaces the issue earlier.

🤖 Generated with Claude Code

@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

⚠️ No Changeset found

Latest commit: eb5c6e4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@whoiskatrin
Copy link
Contributor

@agcty don't merge it just yet, please. Also, can you please fix types in this PR?

Copy link
Contributor

@mattzcarey mattzcarey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking till ci passes :)

@agcty agcty force-pushed the feat/react-version-constraint branch 2 times, most recently from 779ec8d to addd209 Compare December 10, 2025 12:48
@agcty agcty requested a review from mattzcarey December 10, 2025 12:56
@agcty
Copy link
Contributor Author

agcty commented Dec 10, 2025

@whoiskatrin Fixed and tested locally, CI should pass now!

I also added @types/react assuming that's what you meant by "fix types", but the build passes without it too. Let me know if you'd like me to revert that part or if you meant something else!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@723

commit: eb5c6e4

agcty and others added 2 commits December 21, 2025 11:54
The React hooks (`useAgent`, `useAgentChat`) use the `use()` hook which
was introduced in React 19. The previous `"react": "*"` constraint was
misleading since the code will not work with React 18 or earlier.

This change makes the requirement explicit so consumers get a clear
error during installation rather than a confusing runtime error.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@threepointone threepointone force-pushed the feat/react-version-constraint branch from addd209 to eb5c6e4 Compare December 21, 2025 11:55
@threepointone threepointone merged commit 2e73791 into cloudflare:main Dec 21, 2025
3 of 5 checks passed
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.

4 participants