Skip to content

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

Open
waterlemonnn wants to merge 1 commit into
AgentPostmortem:mainfrom
waterlemonnn:fix/copy-link-error-handling
Open

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

Conversation

@waterlemonnn

Copy link
Copy Markdown

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.
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

1 participant