Repository navigation
fix(studio): copy schema behavior on safari - #42293
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
WalkthroughEntityListItem 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
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
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
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 |
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › rls-policies.spec.ts › RLS Policies › Policies Page › should display policies page correctly Skipped testsFeatures › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected |
| setTimeout(() => { | ||
| navigator.clipboard.write([text]).then(callback) | ||
| }, 0) | ||
| navigator.clipboard.write([text]).then(callback) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
asyncbut doesn't return the promise chain, soawait 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) }
02b1335 to
9a0823d
Compare
There was a problem hiding this comment.
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.
| return Promise.resolve(str) | ||
| .then((text) => navigator.clipboard?.writeText(text)) | ||
| .then(callback) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n packages/ui/src/lib/utils/clipboard.tsRepository: 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
left a comment
There was a problem hiding this comment.
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!
Braintrust eval report
|
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.
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
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.