Skip to content

fix: add clipboard fallback for copy actions#66

Merged
overtrue merged 1 commit intomainfrom
overtrue/fix-clipboard-copy-fallback
Feb 27, 2026
Merged

fix: add clipboard fallback for copy actions#66
overtrue merged 1 commit intomainfrom
overtrue/fix-clipboard-copy-fallback

Conversation

@overtrue
Copy link
Collaborator

Fix Windows clipboard copy failures in object pages by adding a shared clipboard helper with fallback path.

  • Add lib/clipboard.ts with navigator.clipboard.writeText primary path and document.execCommand legacy fallback.
  • Reuse helper in copy-input, object path copy button, and object version ID copy.
  • Keep existing success/fail UX and translations unchanged.

This addresses issue #63: Windows 11 copy link failure.

Copilot AI review requested due to automatic review settings February 27, 2026 09:17
@overtrue overtrue merged commit 078cb10 into main Feb 27, 2026
13 checks passed
@overtrue overtrue deleted the overtrue/fix-clipboard-copy-fallback branch February 27, 2026 09:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a shared clipboard helper to address Windows 11/Edge copy failures by providing a legacy document.execCommand("copy") fallback when the Clipboard API is unavailable or denied, and wires it into existing copy UI points.

Changes:

  • Introduce lib/clipboard.ts with copyToClipboard() (Clipboard API primary + legacy fallback).
  • Replace direct navigator.clipboard.writeText calls in object version ID copy, object path copy button, and CopyInput with the shared helper.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
lib/clipboard.ts New shared clipboard helper with fallback copy implementation.
components/object/versions.tsx Uses copyToClipboard() for version ID copy.
components/object/path-links.tsx Uses copyToClipboard() in the path copy hook.
components/copy-input.tsx Uses copyToClipboard() for input copy action.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +47
document.body.appendChild(textarea)
textarea.focus()
textarea.select()

let copied = false
try {
copied = document.execCommand("copy")
} catch {
copied = false
} finally {
document.body.removeChild(textarea)
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacyCopyToClipboard assumes document.body exists and will throw if it’s null (e.g., called very early or in unusual document states). Consider guarding for document.body before appendChild/removeChild and returning false if it’s not available.

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +47
textarea.focus()
textarea.select()

let copied = false
try {
copied = document.execCommand("copy")
} catch {
copied = false
} finally {
document.body.removeChild(textarea)
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The legacy fallback moves focus to a hidden <textarea> (textarea.focus()), which can disrupt keyboard users and screen readers, and focus is not restored afterward. Save the previously focused element and restore focus after copying/removal (or otherwise ensure focus remains on the triggering control).

Copilot uses AI. Check for mistakes.
await navigator.clipboard.writeText(value)
return
} catch (error) {
// Fallback to legacy copy only when Clipboard API is denied or unsupported in current context
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says the legacy path is used "only when Clipboard API is denied or unsupported", but the code falls back on any navigator.clipboard.writeText error. Either narrow the fallback condition (e.g., specific error names) or adjust the comment to match actual behavior.

Suggested change
// Fallback to legacy copy only when Clipboard API is denied or unsupported in current context
// Fallback to legacy copy on any Clipboard API error (e.g., denied or unsupported in current context)

Copilot uses AI. Check for mistakes.
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.

2 participants