fix(start): handle clipboard copy failures#401
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe ChangesClipboard Resilience
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e7619e9 to
dc6293f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/start/src/utils/clipboard.test.ts (1)
57-66: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that success toast is not emitted on full failure.
Add a negative assertion so this test also guards against accidental dual-toast behavior in the failure path.
Suggested patch
it('shows an error when copying is not available', async () => { execCommand.mockReturnValueOnce(false); setClipboardApi(undefined); await clipboard('invite-url'); expect(toast.error).toHaveBeenCalledWith('Failed to copy to clipboard', { description: 'Please copy it manually.', }); + expect(toast).not.toHaveBeenCalled(); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/start/src/utils/clipboard.test.ts` around lines 57 - 66, The failure-path test in clipboard.test.ts should also verify that no success toast is shown when copying is unavailable. Update the existing clipboard test that exercises the missing Clipboard API/execCommand failure path to include a negative assertion against toast.success, alongside the current toast.error check, so the clipboard helper cannot accidentally emit both success and error toasts.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/start/src/utils/clipboard.ts`:
- Around line 19-22: In copyWithTextarea, document.execCommand('copy') can throw
and bypass the existing !copied failure handling; wrap the call so the function
returns false on exception, ensuring fire-and-forget callers still hit the
error-toast path. Keep the cleanup in the finally block intact while updating
the copyWithTextarea flow to treat both a false return and a thrown exception as
copy failure.
---
Nitpick comments:
In `@apps/start/src/utils/clipboard.test.ts`:
- Around line 57-66: The failure-path test in clipboard.test.ts should also
verify that no success toast is shown when copying is unavailable. Update the
existing clipboard test that exercises the missing Clipboard API/execCommand
failure path to include a negative assertion against toast.success, alongside
the current toast.error check, so the clipboard helper cannot accidentally emit
both success and error toasts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 88a7340d-af12-4702-add4-dee257e86765
📒 Files selected for processing (4)
apps/start/src/utils/clipboard.test.tsapps/start/src/utils/clipboard.tsapps/start/vitest.config.tsvitest.workspace.ts
dc6293f to
f0d8fba
Compare
Summary
navigator.clipboard.writeTextis unavailable or rejects.Why
The shared clipboard helper previously called
navigator.clipboard.writeText(...)directly and showed a success toast immediately. In insecure contexts, permission-restricted browser shells, or other unsupported environments, that can fail silently and leave actions like Copy invite link without actually updating the clipboard.Closes #400.
Validation
pnpm exec biome check apps/start/src/utils/clipboard.tspassed.Note
I intentionally left the existing Vitest workspace setup unchanged because
apps/startis currently excluded from the root Vitest workspace.Summary by CodeRabbit