Skip to content

Guard the pledge share clipboard fallback - #72

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixpledge-guard-clipboard-fallback-in-0ffa00
Draft

Guard the pledge share clipboard fallback#72
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixpledge-guard-clipboard-fallback-in-0ffa00

Conversation

@posthog

@posthog posthog Bot commented Aug 29, 2026

Copy link
Copy Markdown

Problem

  • The pledge "Share this pledge" button could fail with no feedback, on the share loop that drives new pledges before the October 26 vote. The user saw the button stay on "Share this pledge" and never learned the link did not copy.
  • After the native share sheet is dismissed, the handler fell through to a bare navigator.clipboard.writeText. The browser rejects that write, because the transient user activation is already gone (NotAllowedError).
  • The rejection surfaced as an unhandled rejection, so setCopied(true) never ran — the "Link copied" state never showed.
  • The same unguarded handler sat in four copies: Toronto, Brampton, Ottawa, and Hamilton.

Changes

  • Add a shared usePledgeShare hook that reports failure instead of failing silently:
    • a dismissed share sheet (AbortError) is treated as done, and the clipboard fallback is skipped — the write would only reject anyway.
    • the clipboard write is wrapped in try/catch and shows a toast on failure, the same pattern already used in ShareButtons.tsx.
  • Replace the four copied share handlers with the one hook. Net 64 fewer lines.

Test plan

  • pnpm run lint — passes.
  • pnpm exec tsc --noEmit — no new type errors (the pre-existing *-stamp.png module errors are unrelated and also hit untouched files).
  • Manual: dismiss the share sheet and confirm the button no longer throws; deny clipboard access and confirm a toast appears.

Created with PostHog Desktop from this inbox report.

The pledge "Share this pledge" button could fail silently. After the native
share sheet is dismissed, the handler fell through to a bare
navigator.clipboard.writeText, which the browser rejects because the transient
user activation is gone. The rejection surfaced as an unhandled rejection, the
copied state never flipped, and the user saw no error.

Move the share behaviour into a shared usePledgeShare hook that:
- treats a dismissed share sheet (AbortError) as done and skips the clipboard,
- wraps the clipboard write in try/catch and shows a toast on failure,
  matching the existing ShareButtons pattern.

The four region pledge pages (Toronto, Brampton, Ottawa, Hamilton) now use the
one hook instead of four copies of the same handler.

Generated-By: PostHog Desktop
Task-Id: 2cb29cbb-01ef-4cdf-8120-ebcaef8571e1
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.

0 participants