Skip to content

Add affiliate dashboard copy fallback - #154

Closed
absalonCRC wants to merge 1 commit into
profullstack:masterfrom
absalonCRC:fix-affiliate-dashboard-copy-fallback
Closed

Add affiliate dashboard copy fallback#154
absalonCRC wants to merge 1 commit into
profullstack:masterfrom
absalonCRC:fix-affiliate-dashboard-copy-fallback

Conversation

@absalonCRC

@absalonCRC absalonCRC commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a resilient affiliate dashboard copy helper with Clipboard API and textarea fallback paths
  • await the copy result before showing the copied state
  • stop click propagation for share-copy buttons inside seller offer links

Closes #153.

This is for the active uGig affiliate/invite testing task: 4741218f-a723-46bb-82cb-6516120331ae.

Payment address for the uGig SOL bounty, if accepted: 27sdMYXofqoM9qR13bZhccRNYeEgYn5EoHXTSJn4QWKP

Validation

  • pnpm exec eslint src/app/dashboard/affiliates/DashboardClient.tsx
  • pnpm type-check
  • git diff --check -- src/app/dashboard/affiliates/DashboardClient.tsx

Payment fallback: PayPal cultofrozen@gmail.com

@greptile-apps

greptile-apps Bot commented May 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens the affiliate dashboard copy flow by introducing a copyText helper that tries the Clipboard API and falls back to a textarea + execCommand approach, then awaits the result before toggling the "Copied!" state. It also fixes click propagation so the share-copy button inside seller offer <Link> cards no longer triggers navigation.

  • Clipboard fallback (copyText): guards the Clipboard API path in a try/catch, but the execCommand branch's inner try has no catch — a SecurityError thrown there would escape as an unhandled promise rejection.
  • CopyButton fix: correctly adds e.stopPropagation() alongside the existing e.preventDefault(), preventing the enclosing <Link> from navigating when the copy button is clicked inside seller offer cards.

Confidence Score: 3/5

Safe to merge once the missing catch in the textarea fallback path is addressed; all other changes are correct.

The copyText textarea fallback can throw a SecurityError or InvalidStateError that has no catch, causing a silent unhandled promise rejection and leaving users with no "Copied!" feedback — a real defect on the changed path.

src/app/dashboard/affiliates/DashboardClient.tsx — specifically the copyText textarea fallback block (lines 67–71).

Important Files Changed

Filename Overview
src/app/dashboard/affiliates/DashboardClient.tsx Adds a copyText helper with Clipboard API + textarea fallback; updates CopyButton to await the result and add stopPropagation. The textarea fallback path lacks a catch, meaning a SecurityError from execCommand would escape as an unhandled promise rejection.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User clicks CopyButton] --> B{stopPropagation?}
    B -- Yes --> C[e.preventDefault + e.stopPropagation]
    B -- No --> D[await copyText]
    C --> D
    D --> E{navigator.clipboard available?}
    E -- Yes --> F[clipboard.writeText]
    F -- Success --> G[return true]
    F -- Throws --> H[catch: fall through]
    H --> I[textarea fallback]
    E -- No --> I
    I --> J[document.body.appendChild textarea]
    J --> K[textarea.select]
    K --> L[execCommand copy]
    L -- Success --> M[finally: removeChild]
    L -- Throws SecurityError --> N[⚠️ unhandled exception propagates]
    M --> O{result true?}
    N --> P[Unhandled promise rejection]
    O -- Yes --> Q[setCopied true, timeout 2s]
    O -- No --> R[No UI feedback]
Loading

Reviews (1): Last reviewed commit: "Add affiliate dashboard copy fallback" | Re-trigger Greptile

Comment on lines +67 to +72
try {
return document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Unhandled exception in textarea fallback path

The inner try/finally for execCommand has no catch. document.execCommand('copy') can throw a SecurityError or InvalidStateError (e.g., in a cross-origin iframe, or when no text is selected). If it does, the exception propagates out of copyText as a rejected Promise, and the async onClick handler has no catch either — producing a silent unhandled promise rejection and leaving the UI without feedback.

Suggested change
try {
return document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
}
try {
return document.execCommand("copy");
} catch {
return false;
} finally {
document.body.removeChild(textarea);
}
}

@ralyodio ralyodio closed this May 23, 2026
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.

bug: affiliate dashboard copy buttons fail when Clipboard API is blocked

2 participants