Skip to content

fix(clipboard): handle fallback copy failures and errors (#384) - #392

Merged
anurag629 merged 2 commits into
codercops:devfrom
bhushan4work:384
Nov 6, 2026
Merged

anurag629 merged 2 commits into
codercops:devfrom
bhushan4work:384

Conversation

@bhushan4work

Copy link
Copy Markdown
Collaborator

description

fix clipboard failure handling in exportbar.tsx and fixitbutton.tsx.

add a shared clipboard helper that checks the result of document.execCommand('copy'), handles thrown exceptions, and cleans up the temporary textarea.

show success notifications only when copying succeeds. display an error notification when both clipboard methods fail.

closes #384

how i tested this

  • npx vitest run tests/editor/export-bar.test.ts tests/editor/export-bar-copy.test.ts tests/components/fix-it-button.test.ts tests/lib/clipboard.test.ts (all 19 tests passed)
  • npx tsc --noEmit (passed with 0 errors)

ai assistance

none

type of change

  • bug fix
  • new template
  • new feature
  • documentation
  • tests
  • refactoring
  • performance improvement
  • other (describe below)

screenshots

not applicable.

checklist

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @bhushan4work, nice work, the shared helper checks what execCommand('copy') returns and catches a throw, so both Copy buttons and the Ctrl/Cmd+Shift+C shortcut in ExportBar.tsx, and the button in FixItButton.tsx, only say it worked when it did, which is what I asked for on #384.

Two small things before I can merge:

  1. src/lib/clipboard.ts:41 exports the helper a second time as copyTextToClipboard, but nothing imports that name (ExportBar.tsx renames it on import), so please drop that line.
  2. Some of the guards in the fallback are only there for the mocked document in the tests. Right after appendChild the textarea's parent is always document.body, so the finally at :28 only needs document.body.removeChild(ta), without the parentNode check and its else if. The typeof document.createElement === 'function' check at :18 can go too, since typeof document !== 'undefined' already covers the server.

Everything else looks good.

@bhushan4work

Copy link
Copy Markdown
Collaborator Author

@anurag629 I have pushed the desired changes . could u plz run a final review before merge

@anurag629 anurag629 added the codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com) label Nov 6, 2026
@anurag629
anurag629 merged commit 5578200 into codercops:dev Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Clipboard fallback reports success even when copying fails

2 participants