mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
aaa1b8c0df
<!-- ccr-slack-attribution --> _Requested by **Pam Chia** · [Slack thread](https://supabase.slack.com/archives/C076KTY11DF/p1789979683276099?thread_ts=1789953317.522459&cid=C076KTY11DF)_ ## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Bug fix. ## What is the current behavior? **Before:** `copyToClipboard` writes text with `navigator.clipboard?.writeText(text)`. When `navigator.clipboard` is undefined — an insecure context, such as self-hosted Studio served over plain http or Studio reached over a LAN IP, where `ClipboardItem` is also undefined so the Safari branch above is skipped — the optional chaining makes the whole expression resolve to `undefined`. Nothing throws, so the `catch` never runs and the success callback on the next line runs anyway. The caller is told the copy succeeded: the UI shows its "Copied!" confirmation state and the copy-tracking telemetry event fires as a successful copy, even though nothing reached the clipboard. That contradicts the documented contract of those events, which are defined as firing only when the clipboard write succeeded. ## What is the new behavior? **After:** the missing-clipboard case fails instead of silently succeeding. The callback does not run, no copy event fires, and the error toast that the function already shows on failure (`Unable to copy to clipboard`) is what the user sees. Every working path behaves exactly as before, including the Safari `ClipboardItem` branch, which is untouched. ## Additional context How: throw when `navigator.clipboard` is missing, inside the `try` block that already exists, so the case lands in the existing `catch` and its error toast rather than falling through to the success path. The now-redundant optional chaining on the write is dropped. One case was added to the existing shared clipboard util tests asserting that the callback does not fire and the error toast shows when the Clipboard API is unavailable; it fails on `master` and passes with this change. Linear: [GROWTH-1261](https://linear.app/supabase/issue/GROWTH-1261/clipboard-copy-helper-reports-success-when-the-clipboard-api-is) --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QdJB22CngN3tpc7Kfdpram Co-authored-by: Claude <noreply@anthropic.com>