Skip to content

fix: add null check for navigator.clipboard across all copy-to-clipboard calls (#2114)#3813

Merged
jpr5 merged 3 commits into
mainfrom
fix/issue-2114
Apr 14, 2026
Merged

fix: add null check for navigator.clipboard across all copy-to-clipboard calls (#2114)#3813
jpr5 merged 3 commits into
mainfrom
fix/issue-2114

Conversation

@jpr5

@jpr5 jpr5 commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #2114

Red-green tested locally.

@changeset-bot

changeset-bot Bot commented Apr 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b472d79

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.

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

@vercel

vercel Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

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 Apr 14, 2026 8:53pm
docs Ready Ready Preview, Comment Apr 14, 2026 8:53pm
form-filling Ready Ready Preview, Comment Apr 14, 2026 8:53pm
research-canvas Ready Ready Preview, Comment Apr 14, 2026 8:53pm
travel Ready Ready Preview, Comment Apr 14, 2026 8:53pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@pkg-pr-new

pkg-pr-new Bot commented Apr 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/a2ui-renderer@3813

@copilotkitnext/angular

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/angular@3813

copilotkit

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/copilotkit@3813

@copilotkit/core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/core@3813

@copilotkit/react-core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-core@3813

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-textarea@3813

@copilotkit/react-ui

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-ui@3813

@copilotkit/runtime

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime@3813

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime-client-gql@3813

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sdk-js@3813

@copilotkit/shared

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/shared@3813

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sqlite-runner@3813

@copilotkit/voice

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/voice@3813

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/web-inspector@3813

commit: fbf1af2

Add null checks for navigator.clipboard across all copy-to-clipboard
calls to prevent TypeError in non-localhost environments where the
Clipboard API is unavailable. The copied indicator now only appears
after a confirmed successful write, preventing false positive UX
feedback when the clipboard API is missing or the write fails.
…plication

Address review feedback: extract the repeated clipboard availability check +
writeText + error handling pattern into a shared copyToClipboard() utility in
@copilotkit/shared. All 9 call sites across angular, react-core, and react-ui
now use the shared utility instead of duplicating the same code block.
@jpr5

jpr5 commented Apr 14, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the feedback about duplicated clipboard code blocks.

What changed: Extracted a shared copyToClipboard(text: string): Promise<boolean> utility into @copilotkit/shared (packages/shared/src/utils/clipboard.ts). It handles:

  • Clipboard API availability check
  • writeText call with error handling
  • Returns true/false for success/failure

All 9 call sites across @copilotkitnext/angular, @copilotkit/react-core, and @copilotkit/react-ui now import and use this shared utility instead of duplicating the same check+write+catch pattern.

Added unit tests for the utility itself in packages/shared/src/utils/__tests__/clipboard.test.ts. All existing tests continue to pass (1076 react-core tests, 136 shared tests, 2 react-ui tests).

The CopyButton in react-core was showing the "copied" checkmark based on
an independent clipboard availability check rather than the actual copy
result. This meant a failed copy (e.g. permission denied) would still
show the success indicator. Now the onClick handler returns the boolean
from copyToClipboard, and handleClick uses that to drive the UI state.
Also removes unsafe type casts of onClick to Promise<void>.
@jpr5 jpr5 merged commit 1e0de53 into main Apr 14, 2026
33 of 43 checks passed
@jpr5 jpr5 deleted the fix/issue-2114 branch April 14, 2026 21:31
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.

Bug: navigator.clipboard undefined in non-localhost environments causes copy functionality to fail

2 participants