CopilotKit icon indicating copy to clipboard operation
CopilotKit copied to clipboard

fix(react-core): refresh thread headers on provider updates

Open sjh9714 opened this issue 5 months ago • 3 comments

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-lockfile
  • pnpm --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.tsx
  • pnpm exec oxlint packages/react-core/src/v2/context.ts packages/react-core/src/v2/hooks/__tests__/use-threads-provider-headers.e2e.test.tsx
  • pnpm exec oxfmt --check packages/react-core/src/v2/context.ts packages/react-core/src/v2/hooks/__tests__/use-threads-provider-headers.e2e.test.tsx
  • pnpm nx run @copilotkit/react-core:build
  • pnpm nx run @copilotkit/react-core:test
  • git commit -m "fix(react-core): refresh thread headers on provider updates" (pre-commit ran pnpm run test && pnpm run check:packages; commit-msg ran pnpm 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)

sjh9714 avatar Jun 06 '26 15:06 sjh9714

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat-with-your-data Ready Ready Preview, Comment Jun 12, 2026 5:50pm
docs Ready Ready Preview, Comment Jun 12, 2026 5:50pm

Request Review

vercel[bot] avatar Jun 06 '26 15:06 vercel[bot]

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 06 '26 15:06 vercel[bot]

Hey @sjh9714, we'll get some eyeballs on this one for review. Thanks!

NathanTarbert avatar Jun 07 '26 11:06 NathanTarbert

Fix LGTM. I'm rebasing and approving the workflows, and we'll try to get this merged today.

BenTaylorDev avatar Jun 12 '26 17:06 BenTaylorDev

Open in StackBlitz

@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

pkg-pr-new[bot] avatar Jun 12 '26 17:06 pkg-pr-new[bot]