Skip to content

fix(studio): copy schema behavior on safari - #42293

Merged
charislam merged 1 commit into
masterfrom
charis/fix/safari-copy
Jan 30, 2026
Merged

charislam merged 1 commit into
masterfrom
charis/fix/safari-copy

Conversation

@charislam

@charislam charislam commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

The clipboard copy operation for table schema would show the success toast before the copy actually completed.

What is the new behavior?

Move the toast showing to the callback so it appears only after the copy finishes

Summary by CodeRabbit

  • Bug Fixes

    • Clipboard success confirmation now appears reliably after the copy completes.
  • New Features

    • Copied table schemas are automatically formatted for improved readability.
  • Improvements

    • Enhanced clipboard behavior for better reliability across browsers.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Jan 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
design-system Ready Ready Preview, Comment Jan 29, 2026 7:02pm
docs Ready Ready Preview, Comment Jan 29, 2026 7:02pm
studio-self-hosted Ready Ready Preview, Comment Jan 29, 2026 7:02pm
studio-staging Ready Ready Preview, Comment Jan 29, 2026 7:02pm
ui-library Ready Ready Preview, Comment Jan 29, 2026 7:02pm
zone-www-dot-com Ready Ready Preview, Comment Jan 29, 2026 7:02pm
2 Skipped Deployments
Project Deployment Review Updated (UTC)
cms Ignored Ignored Jan 29, 2026 7:02pm
studio Ignored Ignored Jan 29, 2026 7:02pm

Request Review

@supabase

supabase Bot commented Jan 29, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

EntityListItem now formats table schema with formatSql before passing it to copyToClipboard and uses a post-copy callback to show a success toast. The clipboard utility removes a setTimeout workaround in the Safari path and adjusts promise resolution for Firefox handling.

Changes

Cohort / File(s) Summary
Table Schema Copy Flow
apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
Format table schema with formatSql prior to copying; pass a success callback into copyToClipboard so the toast is shown after the clipboard write completes.
Clipboard Utility
packages/ui/src/lib/utils/clipboard.ts
Removed setTimeout wrapper in the Safari-compatible path and return the clipboard promise directly; ensure Firefox path returns a Promise.resolve(str) to preserve chaining semantics.

Sequence Diagram(s)

sequenceDiagram
    participant User as rgba(66,133,244,0.5) User
    participant UI as rgba(52,168,83,0.5) EntityListItem
    participant Util as rgba(255,193,7,0.5) copyToClipboard
    participant Browser as rgba(138,43,226,0.5) NavigatorClipboard
    participant Toast as rgba(219,68,55,0.5) Toast

    User->>UI: Click "Copy schema"
    UI->>UI: formatSql(schema)
    UI->>Util: copyToClipboard(formattedSchema, onSuccess)
    Util->>Browser: navigator.clipboard.writeText(formattedSchema)
    Browser-->>Util: write result
    Util-->>UI: resolve (then invoke onSuccess)
    UI->>Toast: show success toast (onSuccess)
    Toast-->>User: visual confirmation
Loading

Possibly related PRs

Suggested reviewers

  • joshenlim
  • awaseem
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(studio): copy schema behavior on safari' clearly describes the main change - fixing a copy schema behavior issue specific to Safari.
Description check ✅ Passed The PR description covers all required template sections: CONTRIBUTING.md confirmation, change type (bug fix), current behavior, and new behavior with clear explanation of the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls

coveralls commented Jan 29, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 66.74%. remained the same
when pulling 9a0823d on charis/fix/safari-copy
into ca7e697 on master.

@github-actions

github-actions Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  83 passed
flaky  3 flaky
skipped  4 skipped

Details

stats  90 tests across 14 suites
duration  13 minutes, 43 seconds
commit  9a0823d

Flaky tests

Features › rls-policies.spec.ts › RLS Policies › Policies Page › should display policies page correctly
Features › rls-policies.spec.ts › RLS Policies › Create RLS Policy › should create a SELECT policy successfully
Features › rls-policies.spec.ts › RLS Policies › Create RLS Policy › should create an INSERT policy with authenticated role

Skipped tests

Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

Comment thread packages/ui/src/lib/utils/clipboard.ts Outdated
setTimeout(() => {
navigator.clipboard.write([text]).then(callback)
}, 0)
navigator.clipboard.write([text]).then(callback)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tested on Safari and seems like the setTimeout might not be needed? The ClipboardItem thing seems to solve it, and the timeout makes the behavior with awaits unexpected

@charislam
charislam marked this pull request as ready for review January 29, 2026 18:47
@charislam
charislam requested review from a team as code owners January 29, 2026 18:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ui/src/lib/utils/clipboard.ts (1)

13-33: Return the clipboard promise so callers can await/fail correctly.

The function is marked async but doesn't return the promise chain, so await copyToClipboard(...) resolves immediately without waiting for the write to complete. Callers using try/catch (e.g., EntityListItem.tsx) won't catch clipboard failures. Return the promise in both branches.

Proposed fix
       const text = new ClipboardItem({
         'text/plain': Promise.resolve(str).then((text) => new Blob([text], { type: 'text/plain' })),
       })
-      navigator.clipboard.write([text]).then(callback)
+      return navigator.clipboard.write([text]).then(callback)
     } else {
       // NOTE: Firefox has support for ClipboardItem and navigator.clipboard.write,
       // but those are behind `dom.events.asyncClipboard.clipboardItem` preference.
       // Good news is that other than Safari, Firefox does not care about
       // Clipboard API being used async in a Promise.
-      Promise.resolve(str)
+      return Promise.resolve(str)
         .then((text) => navigator.clipboard?.writeText(text))
         .then(callback)
     }

@charislam
charislam force-pushed the charis/fix/safari-copy branch from 02b1335 to 9a0823d Compare January 29, 2026 18:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/ui/src/lib/utils/clipboard.ts`:
- Around line 31-33: The current Promise chain uses
navigator.clipboard?.writeText(text) which silently returns undefined when the
API is missing; update the non-Safari branch so you explicitly check
navigator.clipboard and typeof navigator.clipboard.writeText === 'function'
before calling writeText, and if missing return/throw a rejected Promise (e.g.,
Promise.reject(new Error('clipboard API unavailable'))) so the .then(callback)
is not executed erroneously; locate the Promise.resolve(str).then((text) =>
navigator.clipboard?.writeText(text)).then(callback) sequence and replace the
optional chaining call with the explicit guard and rejection.

Comment on lines +31 to 33
return Promise.resolve(str)
.then((text) => navigator.clipboard?.writeText(text))
.then(callback)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n packages/ui/src/lib/utils/clipboard.ts

Repository: supabase/supabase

Length of output: 2112


Guard when navigator.clipboard.writeText is unavailable to avoid false success.

The non-Safari branch uses optional chaining without an explicit availability check. If navigator.clipboard.writeText is unavailable, the optional chain returns undefined and the promise continues to execute the callback without error or rejection, giving a false success signal. This differs from the Safari branch (line 16), which explicitly checks availability first. Add an explicit guard to reject or notify the user when the API is unavailable.

🔧 Suggested guard
-      return Promise.resolve(str)
-        .then((text) => navigator.clipboard?.writeText(text))
-        .then(callback)
+      if (!navigator.clipboard?.writeText) {
+        toast.error('Unable to copy to clipboard')
+        return Promise.reject(new Error('Clipboard API unavailable'))
+      }
+      return Promise.resolve(str)
+        .then((text) => navigator.clipboard.writeText(text))
+        .then(callback)
🤖 Prompt for AI Agents
In `@packages/ui/src/lib/utils/clipboard.ts` around lines 31 - 33, The current
Promise chain uses navigator.clipboard?.writeText(text) which silently returns
undefined when the API is missing; update the non-Safari branch so you
explicitly check navigator.clipboard and typeof navigator.clipboard.writeText
=== 'function' before calling writeText, and if missing return/throw a rejected
Promise (e.g., Promise.reject(new Error('clipboard API unavailable'))) so the
.then(callback) is not executed erroneously; locate the
Promise.resolve(str).then((text) =>
navigator.clipboard?.writeText(text)).then(callback) sequence and replace the
optional chaining call with the explicit guard and rejection.

@dnywh dnywh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested on staging on both Chrome and Safari. Works great on Chrome. Safari now flashes an error toast if focus is blurred before the copy is complete, but weirdly only if I press a key on the keyboard.

Approving because it’s still a big improvement on what’s currently in prod!

@charislam
charislam merged commit 9aced55 into master Jan 30, 2026
17 checks passed
@charislam
charislam deleted the charis/fix/safari-copy branch January 30, 2026 19:14
@github-actions

github-actions Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1769800551)

Score Average Improvements Regressions
Completeness 91.7% (-8pp) - 1 🔴
Conciseness 0% (+0pp) - -
Docs Faithfulness 50% (-8pp) - -
Goal Completion 91.7% (+0pp) 1 🟢 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+20pp) 1 🟢 -
Tool Usage 100% (+0pp) - -
Correctness 87.5% (-12pp) - 1 🔴
URL Validity 100% (+0pp) - -
Time_to_first_token 0.19tok (-0.03tok) 9 🟢 3 🔴
Llm_calls 8.58 (+0.33) 3 🟢 1 🔴
Tool_calls 3.5 (+0.67) 3 🟢 2 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 97442.67tok (+6803.83tok) 4 🟢 8 🔴
Prompt_cached_tokens 45120tok (-1706.67tok) 4 🟢 6 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Completion_tokens 5681.83tok (-111.17tok) 5 🟢 7 🔴
Completion_reasoning_tokens 4149.33tok (-202.67tok) 6 🟢 6 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 103124.5tok (+6692.67tok) 4 🟢 8 🔴
Estimated_cost 0.03$ (+0$) 5 🟢 7 🔴
Duration 57.29s (+6.38s) 4 🟢 8 🔴
Llm_duration 113.34s (+12.65s) 4 🟢 8 🔴

awaseem pushed a commit that referenced this pull request Feb 3, 2026
Bug fix

## What is the current behavior?

The clipboard copy operation for table schema would show the success
toast before the copy actually completed.

## What is the new behavior?

Move the toast showing to the callback so it appears only after the copy
finishes

## Summary

* **Bug Fixes**
* Clipboard success confirmation now appears reliably after the copy
completes.

* **New Features**
* Copied table schemas are automatically formatted for improved
readability.

* **Improvements**
  * Enhanced clipboard behavior for better reliability across browsers.
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.

4 participants