fix: safely copy text when Clipboard API is unavailable - #503
Conversation
|
@Moviw is attempting to deploy a commit to the Raphael's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for this — the direction is right and the implementation is clean. Extracting a single copyTextToClipboard() helper, trying the Clipboard API first and falling back to textarea + execCommand('copy'), with finally-guaranteed cleanup, is exactly what #444 needs. Two things I verified locally and liked: No bare navigator.clipboard calls are left anywhere on the branch — the sweep across Workspace, Go Web, Studio and Launcher is genuinely complete as of the base commit. Blocking: the branch is stale and no longer merges CONFLICT (modify/delete): packages/launcher/src/renderer/components/agent-detail/AgentDetail.tsx — deleted in develop While rebasing, there are 6 new call sites on develop that didn't exist at your base and still call navigator.clipboard directly. They'd need the same treatment for the fix to stay complete: workspace/frontend/components/layout/user-menu.tsx (2 occurrences) const textArea = document.createElement('textarea'); try { This matters more than it might seem: a non-secure HTTP origin on iOS is precisely a case where navigator.clipboard is undefined, so it's squarely in this PR's target scenario. Incidentally, the test helper already mocks setAttribute and setSelectionRange even though the implementation never calls them — I suspect an earlier draft had this and it got trimmed. Smaller points (non-blocking) The removed SSR guard. The three use-copy-to-clipboard.ts hooks dropped if (typeof window === 'undefined' || ...) return;, and the helper's first statement is navigator.clipboard?.writeText. Under Node 20 (what Next 16 targets) navigator is not merely undefined — the bare identifier throws ReferenceError. In practice this only runs from click handlers so the risk is low, but the zero-cost version is: if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) { On the four duplicated files — I looked into whether these should be a shared module, and I don't think they should. There's no root package.json or pnpm-workspace.yaml; these are four independent npm projects, so introducing a shared package would be a much larger change. Copying is the right call here. Overall: rebase, extend to the new call sites, and fix the iOS selection, and this is good to go. Nice, well-scoped contribution — thanks for tackling it. |
7b70084 to
a884aad
Compare
a884aad to
0fb7a11
Compare
Summary
Fix clipboard operations when
navigator.clipboardis unavailable or rejects the write, such as on non-secure HTTP origins.document.execCommand("copy")Testing
Fixes #444