fix(ai-react): sync tools to ChatClient when tools prop changes - #776
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesuseChat option syncing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@AlemTuzlak |
|
@manish-baghel i'll apply this to other frameworks and get it over the finish line, tysm! |
|
Thanks @AlemTuzlak and thanks @citizen204 for raising a PR. Really appreciate it~! |
Sync each wire-payload slot (body, forwardedProps, tools, context) in its own effect so changing one option no longer re-runs the others. Previously a context/body change would needlessly rebuild the client tool registry and fire notifyToolsChanged. Addresses CodeRabbit review feedback on TanStack#776. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit ef3ff0c
☁️ Nx Cloud last updated this comment at |
tombeckenham
left a comment
There was a problem hiding this comment.
Thanks for this and for the comment. I implemented the suggestion
@tanstack/ai
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-mcp
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
Summary
useChatinitialises theChatClientwith thetoolsoption passed at construction time, but never callsclient.updateOptions({ tools })when thetoolsprop changes during the component lifecycle. This means the client-side tool registry becomes stale when callers swap tools — e.g. a project-management app whereupdateTaskToolcloses overprojectIdand the user switches projects.ChatClient.updateOptions()already acceptstoolsand rebuildsclientToolsRefwhen it receives them. The fix is to addtoolsto the existingupdateOptionseffect that already syncsbody,forwardedProps, andcontext.Changes
packages/ai-react/src/use-chat.ts: conditionally spreadoptions.toolsinto theupdateOptionscall and add it to the dependency array, matching the existing pattern forforwardedProps.Fixes #775
Test plan
useChatwith atoolsarray that closes over a value (e.g.projectId).projectIdwhile the component stays mounted.useMemotheir tools array (as shown in the issue) to avoid unnecessary re-registrations.Summary by CodeRabbit