Skip to content

fix(clipboard): Prevent unhandled promise rejection from NotAllowedError - #121032

Draft
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/clipboard-unhandled-rejection-FUnWgY
Draft

fix(clipboard): Prevent unhandled promise rejection from NotAllowedError#121032
sentry[bot] wants to merge 2 commits into
masterfrom
seer/fix/clipboard-unhandled-rejection-FUnWgY

Conversation

@sentry

@sentry sentry Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issue JAVASCRIPT-3B6G, where NotAllowedError from navigator.clipboard.writeText() was causing unhandled promise rejections.

Root Cause:
The copyToClipboard function in useCopyToClipboard.tsx would re-throw the NotAllowedError after displaying an error toast. Since many callers use copy(...) in a fire-and-forget manner without chaining a .catch(), this re-throw resulted in unhandled promise rejections being reported to Sentry.

Changes:

  1. static/app/utils/useCopyToClipboard.tsx:
    • Removed throw error from the .catch() block. The error toast already provides user feedback, so re-throwing is unnecessary and causes the unhandled rejection.
    • Updated the CopyCallback and copyToClipboard return types to Promise<string | void> to reflect that the promise now resolves (to void) on a clipboard error, rather than rejecting.
  2. static/app/components/copyToClipboardButton.tsx:
    • Modified the .then() handler to explicitly check if the resolved value is undefined. If it is, it indicates a copy failure (where the error was handled internally by copyToClipboard), and the onError callback is now invoked with a generic error. This maintains the expected onError behavior for components using CopyToClipboardButton.

CI Fixes:

  • Renamed the unused error parameter to _error in useCopyToClipboard.tsx to resolve a TypeScript TS6133 error.
  • Refactored a conditional statement in copyToClipboardButton.tsx to address an ESLint unicorn/no-negated-condition error.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes JAVASCRIPT-3B6G

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Story previews

Preview the stories changed in this PR on the Vercel deployment:

Preview deployment: https://sentry-g1wt2iv6v.sentry.dev

@sentry sentry Bot changed the title fix(clipboard): Prevent unhandled promise rejection from copyToClipboard fix(clipboard): Prevent unhandled promise rejection from NotAllowedError Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants