Repository navigation
fix(studio): schema copy bug in safari - #42161
Conversation
The schema could not be copied to clipboard in Safari because of the known problem where Safari does not allow awaits to happen before copyToClipboard. Fixed by passing the promise directly to copyToClipboard.
|
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. |
WalkthroughAdds a new ESLint rule preventing calling copyToClipboard after an await and enables it in the Next.js ESLint config; refactors a TableEditor component to use a promise .then() chain when retrieving/formatting table SQL before copying to clipboard and routing errors into existing handlers. Changes
Sequence Diagram(s)mermaid 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx`:
- Around line 270-277: In EntityListItem.tsx the .then() handler currently
returns an empty string when tableDefinition is falsy, which resolves the
promise and lets copyToClipboard and the success toast run; instead throw an
error to reject the promise so the existing catch block handles it. Replace the
branch that does toast.error(...); return '' with code that calls
toast.error(...); then throws a new Error (e.g., new Error('Failed to get table
schema')) so that the promise returned by the chain (the value passed into
formatSql / copyToClipboard) is rejected and the success toast in the copy flow
is not shown; reference formatSql, copyToClipboard, tableDefinition and toastId
when making the change.
🧹 Nitpick comments (1)
packages/eslint-config-supabase/rules/no-await-before-copy-to-clipboard.js (1)
85-91: Consider trackingfor await...ofas an async boundary.The rule currently only tracks
AwaitExpressionnodes. However,for await...ofloops are represented in ESLint's AST asForOfStatementnodes withawait: true, not asAwaitExpressionnodes. This means they're missed even though they create async boundaries that break the synchronous-with-user-gesture requirement for Safari clipboard operations.For example, this would not be flagged:
async function handleClipboard() { for await (const item of getItems()) { process(item) } copyToClipboard(data) // clipboard op is not sync with gesture }♻️ Suggested update
// Record all await expressions AwaitExpression(node) { const funcScope = getFunctionScope(node) if (funcScope && functionScopes.has(funcScope)) { functionScopes.get(funcScope).awaitExpressions.push(node) } }, + + // Record `for await...of` loops as async boundaries + ForOfStatement(node) { + if (!node.await) return + const funcScope = getFunctionScope(node) + if (funcScope && functionScopes.has(funcScope)) { + functionScopes.get(funcScope).awaitExpressions.push(node) + } + },
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › database.spec.ts › Database › Schema Visualizer › actions works as expected Skipped testsFeatures › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected |
| }).then((tableDefinition) => { | ||
| if (!tableDefinition) { | ||
| throw new Error('Failed to get table schema') | ||
| } | ||
|
|
||
| return formatSql(tableDefinition) |
There was a problem hiding this comment.
hmm the changes here unfortunately broke for chrome now 😕
copying is working on safari but not for chrome
There was a problem hiding this comment.
ahh found the issue - just needed to remove the await on copyToClipboard
There was a problem hiding this comment.
hmmm actually sorry i think the await might not have been it (altho okay to remove since i think it's unneccesary), but rather the success toast is showing up before the table definition was fetched
hence why i thought the copy wasn't working, but it was just delayed 😅
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx`:
- Around line 277-282: Replace the ineffective try/catch around copyToClipboard
with the callback pattern used elsewhere: call copyToClipboard(formattedSchema,
() => toast.success('Table schema copied to clipboard', { id: toastId }));
remove the immediate toast.success from the current block and instead report
failures via the existing toast.error where appropriate (or adjust
copyToClipboard to accept an error callback if you need to surface clipboard
failures); reference the copyToClipboard call, formattedSchema,
toast.success/toast.error and toastId when making the change.
| try { | ||
| const formatted = formatSql(tableDefinition) | ||
| await copyToClipboard(formatted) | ||
| copyToClipboard(formattedSchema) | ||
| toast.success('Table schema copied to clipboard', { id: toastId }) | ||
| } catch (err: any) { | ||
| toast.error('Failed to copy schema: ' + (err.message || err), { | ||
| id: toastId, | ||
| }) | ||
| toast.error('Failed to copy schema: ' + (err.message || err), { id: toastId }) | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find the copyToClipboard function definition
rg -n -B 2 -A 15 "export.*function copyToClipboard|export.*const copyToClipboard" --type ts --type tsxRepository: supabase/supabase
Length of output: 88
🏁 Script executed:
# Also check the specific file being reviewed for full context
cat -n "apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx" | sed -n '250,290p'Repository: supabase/supabase
Length of output: 1949
🏁 Script executed:
# Search for copyToClipboard import/usage in the file
rg -n "copyToClipboard|import" "apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx" | head -20Repository: supabase/supabase
Length of output: 1416
🏁 Script executed:
# Search for copyToClipboard function definition in the codebase
rg -n "function copyToClipboard|const copyToClipboard" -t ts | head -20Repository: supabase/supabase
Length of output: 404
🏁 Script executed:
# Also search in JS/TSX files without type filtering
fd -e ts -e tsx -e js | xargs grep -l "copyToClipboard" | head -10Repository: supabase/supabase
Length of output: 635
🏁 Script executed:
# Search for where copyToClipboard might be imported in EntityListItem.tsx or defined elsewhere
rg -n "copyToClipboard" "apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx" -B 2 -A 2Repository: supabase/supabase
Length of output: 561
🏁 Script executed:
# Read the full copyToClipboard implementation
cat -n "packages/ui/src/lib/utils/clipboard.ts"Repository: supabase/supabase
Length of output: 2360
🏁 Script executed:
# Check if copyToClipboard is actually awaited anywhere in the codebase
rg -n "await copyToClipboard" --type ts --type tsx | head -20Repository: supabase/supabase
Length of output: 88
🏁 Script executed:
# Check ESLint rule about copying to clipboard
cat "packages/eslint-config-supabase/rules/no-await-before-copy-to-clipboard.js"Repository: supabase/supabase
Length of output: 4221
🏁 Script executed:
# Search for copyToClipboard usage with callback parameter
rg -n "copyToClipboard.*,\s*\(" --type ts | head -20Repository: supabase/supabase
Length of output: 2290
🏁 Script executed:
# Search for any error handling patterns with copyToClipboard
rg -n -B 3 -A 3 "copyToClipboard" --type ts | grep -A 3 -B 3 "catch\|then\|error" | head -40Repository: supabase/supabase
Length of output: 2930
🏁 Script executed:
# Check if copyToClipboard callback approach handles errors
cat -n "packages/ui/src/lib/utils/clipboard.ts" | sed -n '13,42p'Repository: supabase/supabase
Length of output: 1746
🏁 Script executed:
# Look at one example to see the full error handling pattern
cat -n "apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/CopyEnvButton.tsx" | sed -n '30,45p'Repository: supabase/supabase
Length of output: 719
Use the callback pattern for proper error handling; the proposed .then()/.catch() approach won't work.
The try/catch is ineffective because copyToClipboard() is not awaited and doesn't return a chainable promise. The success toast fires immediately before the clipboard operation completes. Replace with the callback pattern used throughout the codebase:
copyToClipboard(formattedSchema, () => {
toast.success('Table schema copied to clipboard', { id: toastId })
})However, note that copyToClipboard only supports a success callback—it has no error callback parameter and silently swallows clipboard operation errors. Error handling for edge cases (e.g., when getTableDefinition() rejects) would require either modifying copyToClipboard to support error callbacks or wrapping the entire operation differently.
🤖 Prompt for AI Agents
In `@apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx` around
lines 277 - 282, Replace the ineffective try/catch around copyToClipboard with
the callback pattern used elsewhere: call copyToClipboard(formattedSchema, () =>
toast.success('Table schema copied to clipboard', { id: toastId })); remove the
immediate toast.success from the current block and instead report failures via
the existing toast.error where appropriate (or adjust copyToClipboard to accept
an error callback if you need to surface clipboard failures); reference the
copyToClipboard call, formattedSchema, toast.success/toast.error and toastId
when making the change.
joshenlim
left a comment
There was a problem hiding this comment.
Verified changes on preview safari and chrome!
Although JFYI the success toast can show up too quickly before the content has been copied to the clipboard (due to the async nature of getting the table definition) - so initially i thought that the copy wasn't working on Chrome, but it was just delayed 😅
It definitely fixes things for safari though approving nonetheless
Braintrust eval report
|
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Schema could not be copied to clipboard in Safari due to Safari's restriction on awaits before
copyToClipboard.What is the new behavior?
Schema copies correctly in Safari by passing the promise directly to
copyToClipboard. Also adds an ESLint rule to catch asynccopyToClipboardcalls.Additional context
Resolves FE-2403
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.