Skip to content

fix: handle clipboard write failures in copy-link buttons - #66

Merged
royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
waterlemonnn:fix/copy-link-error-handling
Aug 7, 2026
Merged

fix: handle clipboard write failures in copy-link buttons#66
royalpinto007 merged 1 commit into
AgentPostmortem:mainfrom
waterlemonnn:fix/copy-link-error-handling

Conversation

@waterlemonnn

Copy link
Copy Markdown
Contributor

What & why

CopyLinkButton and CommentAnchorLink called navigator.clipboard.writeText() without awaiting or catching it, then unconditionally set copied to true. writeText rejects on insecure origins, unfocused documents, or denied clipboard permission, so the UI could claim success while nothing was actually copied.

Changes

  • Made both copy handlers async and await writeText inside try/catch.
  • On failure, set a new failed state and render a short message instead of "Copied" (CopyLinkButton shows "Could not copy, copy the URL from the address bar"; CommentAnchorLink shows "Failed" given its compact #-sized layout).
  • Guard for navigator.clipboard being undefined before calling it.

Checklist

  • Focused change with a clear description
  • Ran format / lint / tests (see README) — next lint, tsc --noEmit, vitest run (87/87) all clean
  • Updated docs or CHANGELOG if relevant — not applicable, no user-facing docs cover this
  • Linked any related issue (e.g. Closes #123)

Closes #27

navigator.clipboard.writeText() rejects on insecure origins, unfocused
documents, or denied permission. Both CopyLinkButton and
CommentAnchorLink now await the call in a try/catch and surface a
failure state instead of unconditionally claiming success.
@royalpinto007
royalpinto007 merged commit ece0d71 into AgentPostmortem:main Aug 7, 2026
11 checks passed
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

This is in, @waterlemonnn. Really appreciate it.

Good, focused change. Exactly the kind of thing agentpostmortem needs.

If agentpostmortem is useful to you, a star goes a long way.

Happy to see more from you whenever you have the time.

royalpinto007 added a commit to waterlemonnn/agentpostmortem that referenced this pull request Aug 7, 2026
AgentPostmortem#66 landed first and added a "Failed" state to the same button this
branch makes accessible, so the two collided on one line.

Resolved by combining them rather than picking a side: the visible span
still shows Copied / Failed / #, and the sr-only live region now
announces "Failed to copy" as well as "Copied". Taking either side alone
would have dropped one of the two fixes.
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.

Copy-link buttons report success even when the clipboard write fails

2 participants