Skip to content

fix(studio): schema copy bug in safari - #42161

Merged
joshenlim merged 7 commits into
masterfrom
charis/fix/schema-copy-safari
Jan 27, 2026
Merged

joshenlim merged 7 commits into
masterfrom
charis/fix/schema-copy-safari

Conversation

@charislam

@charislam charislam commented Jan 26, 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?

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 async copyToClipboard calls.

Additional context

Resolves FE-2403

Summary by CodeRabbit

  • Bug Fixes

    • Improved "Copy table schema" behavior: schema is formatted asynchronously and the copy flow now uses unified error handling for more consistent success/failure behavior.
  • Chores

    • Added a lint rule to flag calling copy-to-clipboard after awaited operations, helping avoid platform clipboard issues and improve code reliability.

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

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.
@vercel

vercel Bot commented Jan 26, 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 27, 2026 3:31am
docs Ready Ready Preview, Comment Jan 27, 2026 3:31am
studio-self-hosted Ready Ready Preview, Comment Jan 27, 2026 3:31am
studio-staging Ready Ready Preview, Comment Jan 27, 2026 3:31am
ui-library Ready Ready Preview, Comment Jan 27, 2026 3:31am
zone-www-dot-com Ready Ready Preview, Comment Jan 27, 2026 3:31am
2 Skipped Deployments
Project Deployment Review Updated (UTC)
cms Ignored Ignored Jan 27, 2026 3:31am
studio Ignored Ignored Jan 27, 2026 3:31am

Request Review

@supabase

supabase Bot commented Jan 26, 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 26, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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

Cohort / File(s) Summary
Custom ESLint Rule
packages/eslint-config-supabase/rules/no-await-before-copy-to-clipboard.js
New ESLint rule that detects await expressions in async function scopes and reports when copyToClipboard is called after an await.
ESLint Configuration
packages/eslint-config-supabase/next.js
Adds no-await-before-copy-to-clipboard rule to a supabase plugin and enables supabase/no-await-before-copy-to-clipboard as an error in the TypeScript config.
Component Logic
apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
Replaces an awaited getTableDefinition call with a Promise .then() chain that calls formatSql and passes the formatted result to copyToClipboard; errors flow to existing catch/toast handling.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant User
participant UI as TableEditor UI
participant API as getTableDefinition()
participant Formatter as formatSql()
participant Clipboard as copyToClipboard()
participant Toasts

User->>UI: Click "Copy table schema"
UI->>API: getTableDefinition(tableId)
API-->>UI: Promise resolves with tableDefinition
UI->>Formatter: formatSql(tableDefinition)
Formatter-->>UI: formattedSchema
UI->>Clipboard: copyToClipboard(formattedSchema)
Clipboard-->>UI: success / failure
UI->>Toasts: show success or error toast

Possibly related PRs

Suggested reviewers

  • awaseem
  • alaister
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing a Safari schema copy bug by addressing clipboard restrictions.
Description check ✅ Passed The PR description follows the template structure and provides all required information: confirms CONTRIBUTING.md review, specifies bug fix type, explains current behavior with Safari restriction, describes new behavior with promise-based approach and ESLint rule, and references relevant issue FE-2403.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

@charislam
charislam marked this pull request as ready for review January 26, 2026 13:51
@charislam
charislam requested a review from a team as a code owner January 26, 2026 13:51
@coveralls

coveralls commented Jan 26, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 66.134%. remained the same
when pulling ec3e885 on charis/fix/schema-copy-safari
into 9a50688 on master.

@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 `@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 tracking for await...of as an async boundary.

The rule currently only tracks AwaitExpression nodes. However, for await...of loops are represented in ESLint's AST as ForOfStatement nodes with await: true, not as AwaitExpression nodes. 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)
+        }
+      },

@github-actions

github-actions Bot commented Jan 26, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  84 passed
flaky  2 flaky
skipped  4 skipped

Details

stats  90 tests across 14 suites
duration  15 minutes, 29 seconds
commit  046e003

Flaky tests

Features › database.spec.ts › Database › Schema Visualizer › actions works as expected
Features › table-editor.spec.ts › table editor › can create and remove foreign key with column selection

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 on lines +270 to +275
}).then((tableDefinition) => {
if (!tableDefinition) {
throw new Error('Failed to get table schema')
}

return formatSql(tableDefinition)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm the changes here unfortunately broke for chrome now 😕
copying is working on safari but not for chrome

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ahh found the issue - just needed to remove the await on copyToClipboard

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 😅

@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 `@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.

Comment on lines 277 to 282
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 })
}

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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find the copyToClipboard function definition
rg -n -B 2 -A 15 "export.*function copyToClipboard|export.*const copyToClipboard" --type ts --type tsx

Repository: 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 -20

Repository: 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 -20

Repository: 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 -10

Repository: 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 2

Repository: 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 -20

Repository: 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 -20

Repository: 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 -40

Repository: 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 joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@joshenlim
joshenlim merged commit 3fcc8b5 into master Jan 27, 2026
14 checks passed
@joshenlim
joshenlim deleted the charis/fix/schema-copy-safari branch January 27, 2026 07:05
@github-actions

github-actions Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1769497631)

Score Average Improvements Regressions
Completeness 87.5% (-12pp) - 1 🔴
Conciseness 0% (+0pp) - -
Goal Completion 62.5% (-19pp) 1 🟢 3 🔴
Tool Usage 75% (+13pp) 1 🟢 -
SQL Validity 100% - -
Correctness 66.7% (-33pp) - 1 🔴
Docs Faithfulness 50% (-25pp) - 1 🔴
Time_to_first_token 0.38tok (+0.2tok) - 8 🔴
Llm_calls 8.13 (-0.12) 2 🟢 2 🔴
Tool_calls 2.63 (+0.13) 2 🟢 3 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 75605.5tok (-24229.5tok) 5 🟢 3 🔴
Prompt_cached_tokens 47488tok (+5728tok) 7 🟢 1 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Completion_tokens 5385.25tok (+75.25tok) 3 🟢 5 🔴
Completion_reasoning_tokens 3936tok (+272tok) 3 🟢 5 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 80990.75tok (-24154.25tok) 4 🟢 4 🔴
Estimated_cost 0.02$ (-0.01$) 5 🟢 2 🔴
Duration 44.71s (-11.66s) 6 🟢 2 🔴
Llm_duration 88.23s (-23.85s) 6 🟢 2 🔴

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.

3 participants