Skip to content

feat(sql-editor): add manual save feature preview - #47745

Merged
charislam merged 2 commits into
masterfrom
charis/snippet-manual-save-v1
Jul 9, 2026
Merged

charislam merged 2 commits into
masterfrom
charis/snippet-manual-save-v1

Conversation

@charislam

@charislam charislam commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds an opt-in SQL Editor manual save feature preview that switches the SQL Editor from autosaving every edit to saving only on demand, and hardens the tab-close flow so unsaved edits are handled correctly.

Changes

Feature preview

  • New sqlEditorManualSave flag + UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE local-storage toggle, wired into the Feature Preview modal with an explanatory panel.
  • useIsSqlEditorManualSaveEnabled gates behavior on both the flag and the user's preview opt-in.

Editor toolbar

  • Save button (with Cmd+S) next to Run, plus an autosave status indicator showing dirty/saving/saved state and a shortcut to disable autosave (emits a sql_editor_autosave_disable_clicked telemetry event).

Discard on close

  • Closing a snippet tab with unsaved edits prompts for confirmation and, on confirm, actually discards the local edits and evicts the cached server copy so the snippet reopens clean.

Decouple tab layout from SQL specifics

  • Tabs store gains a generic per-type close-handler registry (registerTabCloseHandler / getCloseConfirmation / closeTabs). The SQL editor registers its discard + confirmation behavior from the save coordinator.
  • Low-level removeTab/removeTabs (rename/move re-keying, stale cleanup) intentionally do not trigger discard.
  • Adds statusOnDiscard lifecycle transition and clearSnippetContent store action.

Testing

  • pnpm --filter=studio typecheck — clean.
  • Added unit tests for the close-handler registry (fires on single/multi close, skips re-keying/cleanup removals, respects tab type, selects confirmation copy, unregisters cleanly).

Summary by CodeRabbit

  • New Features
    • Added a SQL editor manual-save preview with a “Save” button and Cmd+S, plus a modal option to disable manual-save/preview.
    • Added “unsaved changes” tab status indication when manual-save is enabled.
    • Introduced tab-type-specific close confirmations (shown only when needed).
  • Bug Fixes
    • In manual-save mode, closing a SQL tab with unsaved edits now clears local snippet content and refreshes it on reopen.
  • Tests
    • Added coverage for tab close handlers and confirmation behavior.
  • Chores
    • Added a persisted setting allowlist entry and tracked autosave-disable clicks via telemetry.

@charislam
charislam requested review from a team as code owners July 8, 2026 16:35
@vercel

vercel Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 8, 2026 9:02pm
studio-staging Ready Ready Preview, Comment Jul 8, 2026 9:02pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 8, 2026 9:02pm
design-system Skipped Skipped Jul 8, 2026 9:02pm
docs Skipped Skipped Jul 8, 2026 9:02pm
ui-library Skipped Skipped Jul 8, 2026 9:02pm
zone-www-dot-com Skipped Skipped Jul 8, 2026 9:02pm

Request Review

@supabase

supabase Bot commented Jul 8, 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 Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

This PR adds a feature-flagged SQL editor manual-save mode, with preview registration, autosave/save UI, save-mode coordination, and discard confirmation for SQL tab closes.

Changes

SQL Editor Manual Save

Layer / File(s) Summary
Feature flag and preview registration
apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx, apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx, apps/studio/components/interfaces/App/FeaturePreview/SqlEditorManualSavePreview.tsx, apps/studio/components/interfaces/App/FeaturePreview/useFeaturePreviews.ts, packages/common/constants/local-storage.ts, packages/common/telemetry-constants.ts
Adds the manual-save feature-preview hook, registers preview content and storage keys, and defines the telemetry event for disabling autosave.
SQL editor save/autosave UI controls
apps/studio/components/interfaces/SQLEditor/UtilityPanel/AutosaveStatus.tsx, apps/studio/components/interfaces/SQLEditor/UtilityPanel/SaveButton.tsx, apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx, apps/studio/components/interfaces/SQLEditor/SqlTabStatusIndicator.tsx, apps/studio/components/layouts/Tabs/SortableTab.tsx
Adds autosave status, save-button, and tab status-indicator components, then wires them into the utility actions row and tab header with manual-save-specific layout and button state.
Save mode coordination and snippet lifecycle
apps/studio/state/sql-editor/sql-editor-lifecycle.ts, apps/studio/state/sql-editor/sql-editor-state.ts, apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx
Adds discard status handling, snippet-content clearing, and save-coordinator logic that switches between auto and manual mode while registering SQL tab close cleanup and confirmation behavior.
Tab close confirmation infrastructure and dialog
apps/studio/state/tabs.tsx, apps/studio/state/tabs.test.ts, apps/studio/components/layouts/Tabs/Tabs.tsx
Adds tab close-handler registration and confirmation selection in tabs state, verifies the handler flow in tests, and routes tab close actions through a discard confirmation dialog in the tabs layout.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • supabase/supabase#47500: Both PRs touch SQL editor snippet lifecycle and state transitions in apps/studio/state/sql-editor/*.
  • supabase/supabase#47533: Both PRs touch SQL editor UI components and the shared state snapshot used by the manual-save controls.

Suggested reviewers: awaseem, joshenlim, alaister

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is useful but does not follow the required template and omits the current behavior and additional context sections. Rewrite the PR description using the repo template, including YES/NO, change type, current behavior with issue links, new behavior, and additional context/screenshots.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding the SQL editor manual save feature preview.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch charis/snippet-manual-save-v1

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.

@charislam
charislam force-pushed the charis/snippet-manual-save-v1 branch from 2af263a to 2bcb398 Compare July 8, 2026 16:44

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

🧹 Nitpick comments (2)
apps/studio/components/layouts/Tabs/Tabs.tsx (1)

115-160: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value

Bulk-close shows a single-snippet confirmation but discards every dirty tab.

getCloseConfirmation returns only the first matching tab's copy ("You have unsaved changes in this SQL snippet…"), yet confirming here runs tabs.closeTabs(tabsToClose) and discards all of them. When multiple SQL tabs have unsaved edits, the singular wording can mislead the user about how much is being discarded. Consider making the confirmation copy count-aware for the bulk paths.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/components/layouts/Tabs/Tabs.tsx` around lines 115 - 160, The
bulk-close flows in Tabs.tsx use a single-tab confirmation message even when
closeWithConfirmation is called with multiple dirty tabs, so update the copy to
reflect the full set being discarded. Adjust the confirmation logic used by
getCloseConfirmation and the bulk handlers handleCloseOthers and
handleCloseRight so it can detect tabsToClose length and generate count-aware
wording for multiple SQL snippets. Keep the existing behavior of tabs.closeTabs
and router.push, but make the message clear that confirming will discard all
affected unsaved tabs, not just one.
apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx (1)

81-81: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer use() over useContext in new React 19 code.

-  const tabsStore = useContext(TabsStateContext)
+  const tabsStore = use(TabsStateContext)

(update the import from react accordingly). Advisory only.

As per coding guidelines: "Flag forwardRef and useContext in new code — use ref as a regular prop and use() instead."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx` at line 81,
Replace the React context read in sql-editor-save-coordinator by using React
19’s use() instead of useContext, and update the react import to include use
while removing useContext. Locate the TabsStateContext access in the save
coordinator component and keep the behavior the same by reading the context
value through use(TabsStateContext) rather than useContext(TabsStateContext).

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/studio/components/interfaces/SQLEditor/UtilityPanel/AutosaveStatus.tsx`:
- Around line 37-57: The AutosaveStatus component shows the disable autosave
action even when manual save is not actually available, because it relies on
isManualSaveEnabled which is also false for self-hosted or when the ConfigCat
flag is off. Update AutosaveStatus so the Button and its Tooltip are only
rendered when the feature is truly exposed, using IS_PLATFORM or the raw
useFlag('sqlEditorManualSave') value rather than isManualSaveEnabled, and keep
the tracking/selectFeaturePreview behavior unchanged for the valid opt-in case.
- Around line 42-52: The icon-only PowerOff button in AutosaveStatus lacks an
accessible name, so add an aria-label to the Button alongside the existing
tooltip behavior. Update the button in AutosaveStatus to include a descriptive
label matching its action (similar to the icon-only buttons in
UtilityActions.tsx), while keeping the current onClick tracking and feature
preview selection unchanged.

---

Nitpick comments:
In `@apps/studio/components/layouts/Tabs/Tabs.tsx`:
- Around line 115-160: The bulk-close flows in Tabs.tsx use a single-tab
confirmation message even when closeWithConfirmation is called with multiple
dirty tabs, so update the copy to reflect the full set being discarded. Adjust
the confirmation logic used by getCloseConfirmation and the bulk handlers
handleCloseOthers and handleCloseRight so it can detect tabsToClose length and
generate count-aware wording for multiple SQL snippets. Keep the existing
behavior of tabs.closeTabs and router.push, but make the message clear that
confirming will discard all affected unsaved tabs, not just one.

In `@apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx`:
- Line 81: Replace the React context read in sql-editor-save-coordinator by
using React 19’s use() instead of useContext, and update the react import to
include use while removing useContext. Locate the TabsStateContext access in the
save coordinator component and keep the behavior the same by reading the context
value through use(TabsStateContext) rather than useContext(TabsStateContext).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8b73fd95-d152-44a5-9942-185dfd508ac9

📥 Commits

Reviewing files that changed from the base of the PR and between 944c586 and 2af263a.

📒 Files selected for processing (15)
  • apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
  • apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
  • apps/studio/components/interfaces/App/FeaturePreview/SqlEditorManualSavePreview.tsx
  • apps/studio/components/interfaces/App/FeaturePreview/useFeaturePreviews.ts
  • apps/studio/components/interfaces/SQLEditor/UtilityPanel/AutosaveStatus.tsx
  • apps/studio/components/interfaces/SQLEditor/UtilityPanel/SaveButton.tsx
  • apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
  • apps/studio/components/layouts/Tabs/Tabs.tsx
  • apps/studio/state/sql-editor/sql-editor-lifecycle.ts
  • apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx
  • apps/studio/state/sql-editor/sql-editor-state.ts
  • apps/studio/state/tabs.test.ts
  • apps/studio/state/tabs.tsx
  • packages/common/constants/local-storage.ts
  • packages/common/telemetry-constants.ts

@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  232 passed
skipped  5 skipped

Details

stats  237 tests across 27 suites
duration  3 minutes, 39 seconds
commit  abedc76

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
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

@charislam
charislam force-pushed the charis/snippet-manual-save-v1 branch from 2bcb398 to b6be409 Compare July 8, 2026 17:09
Adds an opt-in "SQL Editor manual save" feature preview that switches the
SQL Editor from autosaving every edit to saving only on demand, and hardens
the tab-close flow so unsaved edits are handled correctly.

Feature preview
- New `sqlEditorManualSave` flag + `UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE`
  local-storage toggle, wired into the Feature Preview modal with an
  explanatory preview panel.
- `useIsSqlEditorManualSaveEnabled` gates the behavior on both the flag and
  the user's preview opt-in.

Editor toolbar
- Add a Save button (with Cmd+S) next to Run and an autosave status
  indicator that surfaces dirty/saving/saved state and a shortcut to disable
  autosave, emitting a `sql_editor_autosave_disable_clicked` telemetry event.

Discard on close
- Closing a snippet tab with unsaved edits now prompts for confirmation and,
  on confirm, actually discards the local edits and evicts the cached server
  copy so the snippet reopens clean. This now applies to every close path
  (close, close others, close to the right, close all), not just single close.

Decouple tab layout from SQL specifics
- Give the tabs store a generic, per-type close-handler registry
  (`registerTabCloseHandler` / `getCloseConfirmation` / `closeTabs`). The SQL
  editor registers its discard + confirmation behavior from the save
  coordinator, so the Tabs layout no longer imports snippet state, React Query
  keys, or unsaved-changes semantics. Low-level `removeTab`/`removeTabs`
  (used for rename/move re-keying and stale cleanup) intentionally do not
  trigger discard.
- Add `statusOnDiscard` lifecycle transition and `clearSnippetContent` store
  action to model discarding.

Tests
- Cover the close-handler registry: fires on single/multi close, skips
  re-keying/cleanup removals, respects tab type, selects confirmation copy,
  and unregisters cleanly.
@charislam
charislam force-pushed the charis/snippet-manual-save-v1 branch from b6be409 to e342973 Compare July 8, 2026 17:36
Add a VS Code-style unsaved-changes indicator to SQL editor tabs: a dot
shows at rest when the snippet has unsaved edits and swaps to the close
button on hover.

The tabs layout stays agnostic of snippets. The per-tab-type registry
(previously close-only) is generalized to TabTypeHandler, which can now also
provide a StatusIndicator component; the SQL editor registers one from the
save coordinator. A registration-version signal lets tabs pick up a handler
registered in an effect after first paint.

The dot renders only in manual-save mode when the snippet is dirty (auto
mode persists on its own, so a dot would just flicker), and uses the
`bg-warning` design-system token.
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