fix(ui): safari clipboard fallback for copy as markdown button#2189
fix(ui): safari clipboard fallback for copy as markdown button#2189howwohmm wants to merge 6 commits intonpmx-dev:mainfrom
Conversation
Fixes npmx-dev#2151 Safari requires navigator.clipboard.writeText() to be called synchronously within a user gesture. The async fetchReadmeMarkdown() breaks that chain, causing the clipboard write to silently fail. Added a document.execCommand('copy') fallback via a temporary textarea when the Clipboard API rejects. Also bypassed useClipboard's copy() to directly use navigator.clipboard.writeText() so the rejection is catchable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughReplaces the previous Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 Tip CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.OpenGrep is compatible with Semgrep configurations. Add an |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b55b1cec-5923-49fb-99ba-f3ae41bd8f37
📒 Files selected for processing (1)
app/pages/package/[[org]]/[name].vue
copiedReadme from useClipboard's copied is a read-only computed — direct assignment fails type checking. Since we now bypass useClipboard's copy() entirely, replace with a writable shallowRef. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace writeText() + execCommand fallback with the ClipboardItem Promise pattern. Passing the async fetch as a Promise into ClipboardItem keeps the clipboard.write() call synchronous within the user gesture, which is what Safari requires. Ref: https://wolfgangrittner.dev/how-to-use-clipboard-api-in-safari/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
hey @ghostdevv — this uses the ClipboardItem-with-Promise pattern from the blog post you linked on #2182 (https://wolfgangrittner.dev/how-to-use-clipboard-api-in-safari/). the key difference from #2182 is that the async fetch happens inside the ClipboardItem blob, keeping also has a full fallback chain (writeText → execCommand) for browsers without ClipboardItem Promise support. all CI is green. |
🔗 Linked issue
Fixes #2151
🧭 Context
Safari requires clipboard writes to happen synchronously within a user gesture. The
copyReadmeHandlerdoesawait fetchReadmeMarkdown()before writing to clipboard, breaking that chain — sowriteText()silently rejects.📚 Description
Uses the
ClipboardItemwith Promise pattern: pass the async fetch as a Promise intoClipboardItem, soclipboard.write()stays synchronous within the gesture while the data resolves internally.Fallback chain for older browsers:
writeText()→execCommand('copy').What it doesn't change