fix(react-core): refresh thread headers on provider updates
What does this PR do?
Fixes #5282.
Provider header updates already reach the core instance via setHeaders, but React consumers of useCopilotKit() were only re-rendered for runtime connection status changes. That left useThreads() with stale context after the provider headers prop changed, so subsequent /threads requests could miss headers such as X-CSRF.
This subscribes the React context hook to onHeadersChanged and adds a provider-level regression test that verifies /threads is refetched with the updated header.
Related PRs and Issues
- Fixes https://github.com/CopilotKit/CopilotKit/issues/5282
Testing
pnpm install --frozen-lockfilepnpm --dir packages/react-core exec vitest run src/v2/hooks/__tests__/use-threads-provider-headers.e2e.test.tsx(failed before the production change, passed after)pnpm --dir packages/react-core exec vitest run src/v2/hooks/__tests__/use-threads.test.tsx src/v2/hooks/__tests__/use-threads-provider-headers.e2e.test.tsxpnpm exec oxlint packages/react-core/src/v2/context.ts packages/react-core/src/v2/hooks/__tests__/use-threads-provider-headers.e2e.test.tsxpnpm exec oxfmt --check packages/react-core/src/v2/context.ts packages/react-core/src/v2/hooks/__tests__/use-threads-provider-headers.e2e.test.tsxpnpm nx run @copilotkit/react-core:buildpnpm nx run @copilotkit/react-core:testgit commit -m "fix(react-core): refresh thread headers on provider updates"(pre-commit ranpnpm run test && pnpm run check:packages; commit-msg ranpnpm commitlint --edit)
Also checked: pnpm nx run @copilotkit/react-core:check-types currently fails before checking this package because dependency package type/build errors are reported in @copilotkit/shared and @copilotkit/a2ui-renderer; I did not change those packages.
Note: I used Codex while preparing this change, reviewed the final diff, and ran the listed checks locally.
Checklist
- [x] I have read the Contribution Guide
- [ ] If the PR changes or adds functionality, I have updated the relevant documentation (not applicable: internal header propagation bug fix)
- [x] "Allow edits by maintainers" is checked (lets us help iterate on your PR directly - faster turnaround for everyone)
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| chat-with-your-data | Preview, Comment | Jun 12, 2026 5:50pm | |
| docs | Preview, Comment | Jun 12, 2026 5:50pm |
@sjh9714 is attempting to deploy a commit to the CopilotKit Team on Vercel.
A member of the Team first needs to authorize it.
Hey @sjh9714, we'll get some eyeballs on this one for review. Thanks!
Fix LGTM. I'm rebasing and approving the workflows, and we'll try to get this merged today.
@copilotkit/a2ui-renderer
pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@5300
@copilotkit/agentcore-runner
pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@5300
@copilotkitnext/angular
pnpm add https://pkg.pr.new/@copilotkitnext/angular@5300
@copilotkit/bot
pnpm add https://pkg.pr.new/@copilotkit/bot@5300
@copilotkit/bot-slack
pnpm add https://pkg.pr.new/@copilotkit/bot-slack@5300
@copilotkit/bot-ui
pnpm add https://pkg.pr.new/@copilotkit/bot-ui@5300
@copilotkit/core
pnpm add https://pkg.pr.new/@copilotkit/core@5300
@copilotkit/react-core
pnpm add https://pkg.pr.new/@copilotkit/react-core@5300
@copilotkit/react-native
pnpm add https://pkg.pr.new/@copilotkit/react-native@5300
@copilotkit/react-textarea
pnpm add https://pkg.pr.new/@copilotkit/react-textarea@5300
@copilotkit/react-ui
pnpm add https://pkg.pr.new/@copilotkit/react-ui@5300
@copilotkit/runtime
pnpm add https://pkg.pr.new/@copilotkit/runtime@5300
@copilotkit/runtime-client-gql
pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@5300
@copilotkit/sdk-js
pnpm add https://pkg.pr.new/@copilotkit/sdk-js@5300
@copilotkit/shared
pnpm add https://pkg.pr.new/@copilotkit/shared@5300
@copilotkit/sqlite-runner
pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@5300
@copilotkit/voice
pnpm add https://pkg.pr.new/@copilotkit/voice@5300
@copilotkit/vue
pnpm add https://pkg.pr.new/@copilotkit/vue@5300
@copilotkit/web-inspector
pnpm add https://pkg.pr.new/@copilotkit/web-inspector@5300
commit: 9639b8d