Skip to content

fix(studio): prevent truncation of large values in copy/export operations - #42818

Open
4RH1T3CT0R7 wants to merge 3 commits into
supabase:masterfrom
4RH1T3CT0R7:fix/issue-37151-export-truncation
Open

4RH1T3CT0R7 wants to merge 3 commits into
supabase:masterfrom
4RH1T3CT0R7:fix/issue-37151-export-truncation

Conversation

@4RH1T3CT0R7

@4RH1T3CT0R7 4RH1T3CT0R7 commented Feb 14, 2026 •

Copy link
Copy Markdown

Summary

  • Fix copy-to-clipboard and file export operations in the Table Editor delivering truncated data for large JSONB/text columns
  • The grid correctly truncates values at 10KB for display performance, but this truncated data was leaking into copy and export operations
  • Add fetchSelectedTableRows() that re-fetches specific rows by primary key using SELECT * (no truncation CTE) before copy/export

What changed

File Change
apps/studio/data/table-rows/table-rows-query.ts Add fetchSelectedTableRows function
apps/studio/components/layouts/TableEditorLayout/ExportAllRows.tsx Add fetch_selected export type + handling
apps/studio/components/grid/components/header/Header.tsx Use fetch_selected for export, fetch full data for copy
apps/studio/components/grid/components/header/HeaderNew.tsx Same changes as Header.tsx
apps/studio/components/grid/components/menu/RowContextMenu.tsx Fetch full cell/row data before copying

Affected operations

Operation Before After
Grid display Truncated (correct) No change
Copy selected rows Truncated (bug) Full data
Export selected rows Truncated (bug) Full data
Export ALL rows Full data (correct) No change
Right-click → Copy cell Truncated (bug) Full data
Right-click → Copy row Truncated (bug) Full data

Design decisions

  • Safari compatibility: Uses promise-based copyToClipboard(Promise<string>) pattern instead of await-then-copy, satisfying the no-await-before-copy-to-clipboard lint rule
  • No primary key fallback: Falls back to fetchAllTableRows with current filters (same limitation as the existing "Load" button)
  • Composite PKs: Handled via inTupleFilterSql which produces (col1, col2) IN ((v1, v2), ...)
  • Graceful error handling: On fetch failure, falls back to truncated grid data with a toast warning
  • Empty selection guard: Returns [] immediately if no rows are selected, preventing invalid SQL

Test plan

  • Verify TypeScript typecheck passes (pnpm typecheck - confirmed)
  • Verify lint passes with 0 errors (pnpm lint - confirmed)
  • Create table with JSONB column containing >10KB value
  • Select rows - Copy as CSV/JSON/SQL - verify full data in clipboard
  • Select rows - Export as CSV/JSON/SQL - verify full data in file
  • Right-click - Copy cell on large JSONB - verify full value
  • Right-click - Copy row - verify full row data
  • Verify grid still displays truncated values (no regression)
  • Test with table that has no primary key (fallback behavior)
  • Test with composite primary key table

Fixes #37151
Fixes #42289

Summary by CodeRabbit

Release Notes

  • New Features

    • Copy operations now fetch full row data from the database for complete and accurate results
    • Added support for role impersonation in copy and export workflows
    • New export option to fetch and export selected rows while preserving applied filters and sorts
  • Bug Fixes

    • Improved error handling in copy operations with automatic fallback to local data

…ions

The Table Editor grid truncates large column values (JSONB, text, etc.)
at 10KB for display performance. This truncation was leaking into
copy-to-clipboard and file export operations, causing data loss.

Add `fetchSelectedTableRows()` that re-fetches specific rows by primary
key using `SELECT *` (no truncation CTE). Copy and export operations now
use this function to get full data before formatting output.

Changes:
- Add `fetchSelectedTableRows` to re-fetch rows without truncation
- Add `fetch_selected` export type for selected-row file exports
- Update Header copy/export to fetch full data before output
- Update RowContextMenu to fetch full cell/row data before copying
- Use promise-based `copyToClipboard` pattern for Safari compatibility

Fixes supabase#37151
Fixes supabase#42289
@4RH1T3CT0R7
4RH1T3CT0R7 requested a review from a team as a code owner February 14, 2026 21:21
@vercel

vercel Bot commented Feb 14, 2026

Copy link
Copy Markdown

@4RH1T3CT0R7 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Feb 14, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Error Error Mar 13, 2026 10:47pm

Request Review

@coderabbitai

coderabbitai Bot commented Feb 14, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Introduced asynchronous data enrichment for copy and export operations by adding a fetchSelectedTableRows function that retrieves full row data from the database using primary keys. Updated copy workflows in header, context menu, and export components to fetch server-side row data instead of using client-side truncated subsets, with error handling and role impersonation support.

Changes

Cohort / File(s) Summary
Copy operations in grid components
apps/studio/components/grid/components/header/Header.tsx, apps/studio/components/grid/components/header/HeaderNew.tsx, apps/studio/components/grid/components/menu/RowContextMenu.tsx
Modified onCopyRows to asynchronously fetch full selected rows via fetchSelectedTableRows before formatting to CSV/SQL/JSON. Added project guards, error handling with fallback to local data, role impersonation state support, and updated clipboard operations to use promise-based copying with success toast after completion.
Export configuration and flow
apps/studio/components/layouts/TableEditorLayout/ExportAllRows.tsx
Added new fetch_selected export path variant to UseExportAllRowsParams type that fetches specific selected rows from database with optional filters, sorts, and role impersonation state. Integrated alongside existing provided_rows and fetch_all paths with corresponding error handling for fetch failures and empty result sets.
Row data fetching
apps/studio/data/table-rows/table-rows-query.ts
Introduced fetchSelectedTableRows function to fetch specific rows by primary key without truncation, supporting composite keys, optional filters, sorts, and role impersonation. Handles tables without primary keys by falling back to fetchAllTableRows and validates connection strings on platform builds.

Sequence Diagram(s)

sequenceDiagram
    participant UI as Grid UI<br/>(Header/Menu)
    participant Client as Client Logic<br/>(onCopyRows)
    participant API as Supabase API
    participant DB as Database
    participant Clipboard as Clipboard
    
    UI->>Client: User clicks Copy Rows
    Client->>Client: Guard check: project exists?
    Client->>API: fetchSelectedTableRows(projectRef,<br/>selectedRows, filters, sorts)
    API->>DB: Query rows by PK with<br/>impersonation state
    DB-->>API: Full row data (no truncation)
    API-->>Client: Row[] Promise
    Client->>Client: Format rows to CSV/SQL/JSON
    Client->>Client: Create textPromise
    Client->>Clipboard: copyToClipboard(textPromise)
    Clipboard-->>Client: Copy complete
    Client->>UI: Show success toast
Loading

Possibly related PRs

  • #42293: Modifies clipboard utility and caller patterns to wait for async copy operations to complete before displaying success notifications, aligning with the promise-based copying approach used in this PR.

Suggested reviewers

  • joshenlim
  • awaseem
  • alaister
🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing truncation of large values during copy/export operations, which aligns with the core changes in the PR.
Description check ✅ Passed The description is comprehensive and well-structured, covering the summary, what changed, affected operations, design decisions, and test plan. It maps to the template requirements and provides clear context.
Linked Issues check ✅ Passed The PR addresses all coding requirements from #37151 (CSV export must include full cell contents) and #42289 (exports must contain full JSONB without truncation) by adding fetchSelectedTableRows and updating copy/export operations.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the truncation bug fix: new fetchSelectedTableRows function, updated export handling, and modified copy operations. No unrelated changes are present.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
apps/studio/data/table-rows/table-rows-query.ts (1)

379-381: Consider adding error context when executeSql fails.

The executeSql call can throw, and the error will propagate to callers. While callers (Header.tsx, HeaderNew.tsx, RowContextMenu.tsx) do have .catch() blocks, the raw error from executeSql may not provide sufficient context about which operation failed.

💡 Optional: Wrap with more descriptive error
-  const sql = wrapWithRoleImpersonation(queryChains.toSql(), roleImpersonationState)
-  const { result } = await executeSql({ projectRef, connectionString, sql })
-  return result.filter((row: any) => row[ROLE_IMPERSONATION_NO_RESULTS] !== 1)
+  const sql = wrapWithRoleImpersonation(queryChains.toSql(), roleImpersonationState)
+  try {
+    const { result } = await executeSql({ projectRef, connectionString, sql })
+    return result.filter((row: any) => row[ROLE_IMPERSONATION_NO_RESULTS] !== 1)
+  } catch (error) {
+    throw new Error(
+      `Error fetching selected table rows: ${error instanceof Error ? error.message : 'Unknown error'}`
+    )
+  }
apps/studio/components/grid/components/header/HeaderNew.tsx (1)

301-346: Consider extracting shared copy/export logic.

The onCopyRows function and exportParams construction are duplicated between Header.tsx and HeaderNew.tsx. Consider extracting this logic into a shared hook or utility function to improve maintainability.

💡 Example: Shared hook for copy operations
// hooks/useCopyTableRows.ts
export const useCopyTableRows = ({
  project,
  table,
  allRows,
  selectedRowIdxs,
  filters,
  sorts,
  roleImpersonationState,
}: UseCopyTableRowsParams) => {
  const onCopyRows = useCallback((type: 'csv' | 'json' | 'sql') => {
    if (!project) return

    const selectedRows = allRows.filter((x) => selectedRowIdxs.has(x.idx))
    // ... shared implementation
  }, [project, table, allRows, selectedRowIdxs, filters, sorts, roleImpersonationState])

  return { onCopyRows }
}

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

@pirate

pirate commented Mar 13, 2026 •

Copy link
Copy Markdown

@4RH1T3CT0R7 I believe there are a couple prettier errors blocking this from getting merged:

[warn] apps/studio/components/grid/components/header/Header.tsx
[warn] apps/studio/components/grid/components/header/HeaderNew.tsx

We just hit this export truncation bug in our org, caused a lot of suprising issues because we assumed an export would be complete, almost lost some important data!

Remove unnecessary parentheses in exportParams object literal
to satisfy prettier formatting rules.
@archi980

Copy link
Copy Markdown

@pirate Fixed! Ran prettier --write on all changed files — the issues were import ordering and unnecessary parentheses. Pushed in two follow-up commits.

@pirate

pirate commented Mar 13, 2026

Copy link
Copy Markdown

@awaseem perhaps you may be able to help authorize this PR? (sorry if you're the wrong person to ping)

@4RH1T3CT0R7

Copy link
Copy Markdown
Author

any updates?

This branch has not been deployed

No deployments
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.

Admin console - Cannot edit or correctly export large JSONB values (truncation) Database CSV export cuts off long JSON cells

3 participants