Skip to content

refactor(sql-editor): extract snippet-identity/mount/prettify/title hooks (decompose 3b/6) - #47893

Merged
charislam merged 1 commit into
masterfrom
charislam/sql-editor-decompose-3b-hooks
Jul 13, 2026
Merged

charislam merged 1 commit into
masterfrom
charislam/sql-editor-decompose-3b-hooks

Conversation

@charislam

@charislam charislam commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Continues the SQLEditor decomposition. Pulls four cohesive concerns out of the SQLEditorContent composition root into co-located use* hooks.

New hooks

  • useSnippetIdentity — derives id / generatedNewSnippetName / isLoading from the URL + snippet store (keeps the [urlId] memo dep verbatim).
  • useEditorMount — the editor onMount (scroll restore/track) + the mount counter that lets a pre-mount diff request re-run.
  • usePrettifyQuery — formats the editor SQL in place and writes it back to the store.
  • useSnippetTitleGenerator — the title-generation mutation + setAiTitle.

Summary by CodeRabbit

  • New Features

    • SQL editor now restores the last scroll position when reopening queries.
    • Added SQL prettification to format the query directly in the editor.
    • New snippets use stable identities and can be automatically assigned AI-generated titles.
  • Improvements

    • Refined snippet loading/identity handling and simplified URL-based navigation.
    • Improved diff-view behavior and streamlined title/formatting updates through dedicated editor hooks.

@charislam
charislam requested a review from a team as a code owner July 13, 2026 16:33
@supabase

supabase Bot commented Jul 13, 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 ↗︎.

@vercel

vercel Bot commented Jul 13, 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 13, 2026 6:42pm
studio-staging Ready Ready Preview, Comment Jul 13, 2026 6:42pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 13, 2026 6:42pm
design-system Skipped Skipped Jul 13, 2026 6:42pm
docs Skipped Skipped Jul 13, 2026 6:42pm
ui-library Skipped Skipped Jul 13, 2026 6:42pm
zone-www-dot-com Skipped Skipped Jul 13, 2026 6:42pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ecca711-3c98-45cb-8def-a5842223e97f

📥 Commits

Reviewing files that changed from the base of the PR and between 3c385dc and 1324f12.

📒 Files selected for processing (5)
  • apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
  • apps/studio/components/interfaces/SQLEditor/useEditorMount.ts
  • apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts
  • apps/studio/components/interfaces/SQLEditor/useSnippetIdentity.ts
  • apps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/studio/components/interfaces/SQLEditor/useEditorMount.ts
  • apps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.ts
  • apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts

📝 Walkthrough

Walkthrough

Changes

SQLEditor now uses dedicated hooks for snippet identity, editor mounting, AI title generation, and query prettification. Diff cleanup and scroll persistence use effect-event handlers instead of inline lifecycle logic.

SQLEditor behavior refactor

Layer / File(s) Summary
Snippet identity and title generation
apps/studio/components/interfaces/SQLEditor/useSnippetIdentity.ts, apps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.ts, apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
Snippet IDs, loading state, AI title updates, and related SQLEditor wiring are provided by dedicated hooks.
Editor mount and query formatting
apps/studio/components/interfaces/SQLEditor/useEditorMount.ts, apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts, apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
Editor mount counting, scroll restoration, scroll tracking, and SQL prettification move into reusable hooks.
Diff and scroll lifecycle handling
apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
Diff closing and scroll-position persistence use useEffectEvent handlers in the lifecycle effect.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: alaister, awaseem, djhi, ivasilov, joshenlim

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is useful but misses the repository's required template sections and key fields. Fill in the template sections: CONTRIBUTING.md acknowledgment, change type, current behavior/issues, new behavior, and additional context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: extracting SQL editor concerns into dedicated hooks.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch charislam/sql-editor-decompose-3b-hooks

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.

@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  238 passed
skipped  5 skipped

Details

stats  243 tests across 28 suites
duration  4 minutes, 28 seconds
commit  1324f12

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 charislam/sql-editor-decompose-3-context branch from 1971ee5 to 7667bfb Compare July 13, 2026 16:51
@charislam
charislam force-pushed the charislam/sql-editor-decompose-3b-hooks branch from 13d0915 to d6cfb98 Compare July 13, 2026 16:53
Base automatically changed from charislam/sql-editor-decompose-3-context to master July 13, 2026 17:02
@charislam
charislam force-pushed the charislam/sql-editor-decompose-3b-hooks branch from d6cfb98 to 3c385dc Compare July 13, 2026 17:23

@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

🤖 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/SQLEditor.tsx`:
- Around line 635-646: Update saveScrollPosition to accept the tab identifier as
a parameter while continuing to read the latest ref and tabs values; in the
useEffect cleanup, return an arrow closure that passes the effect’s captured id
to saveScrollPosition, preserving the departing snippet’s tab when switching
ids.
🪄 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: 64c9cc98-3258-4cc4-ae10-fa12fbd01abf

📥 Commits

Reviewing files that changed from the base of the PR and between 2ec8e3b and 3c385dc.

📒 Files selected for processing (5)
  • apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
  • apps/studio/components/interfaces/SQLEditor/useEditorMount.ts
  • apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts
  • apps/studio/components/interfaces/SQLEditor/useSnippetIdentity.ts
  • apps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.ts

…e hooks

Pulls four cohesive concerns out of the SQLEditor composition root into co-located hooks: useSnippetIdentity (id/name/loading derivation), useEditorMount (onMount + mount counter), usePrettifyQuery, and useSnippetTitleGenerator (title mutation + setAiTitle). Behavior-preserving; the characterization suite stays green. PR 3b of the SQLEditor decomposition stack.
@charislam
charislam force-pushed the charislam/sql-editor-decompose-3b-hooks branch from 3c385dc to 1324f12 Compare July 13, 2026 18:37
@charislam
charislam merged commit c9a649c into master Jul 13, 2026
37 checks passed
@charislam
charislam deleted the charislam/sql-editor-decompose-3b-hooks branch July 13, 2026 19:35
@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1783971505)

Score Average Improvements Regressions
Knowledge Usage 96.9% (+2pp) 1 🟢 -
SQL Validity 100% (+4pp) 1 🟢 -
Tool Usage 76.1% (+2pp) 1 🟢 -
SQL Identifier Quoting 100% (+0pp) - -
Time_to_first_token 3.07tok (-0.13tok) 18 🟢 11 🔴
Llm_calls 3.25 (+0.24) 15 🟢 11 🔴
Tool_calls 3.22 (-0.02) 10 🟢 10 🔴
Errors 5.72 (+0.62) 1 🟢 17 🔴
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 25317.57tok (+880.89tok) 14 🟢 12 🔴
Prompt_cached_tokens 8651.03tok (+1247.63tok) 15 🟢 9 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 604.08tok (+8.9tok) 18 🟢 11 🔴
Completion_reasoning_tokens 97.44tok (-4.63tok) 19 🟢 7 🔴
Total_tokens 25921.66tok (+889.78tok) 16 🟢 13 🔴
Estimated_cost 0$ (+0$) 12 🟢 14 🔴
Duration 16.01s (-2.75s) 18 🟢 11 🔴
Llm_duration 12.05s (+1.1s) 15 🟢 14 🔴

joshenlim pushed a commit that referenced this pull request Jul 14, 2026
…ooks (decompose 3b/6) (#47893)

## Summary

Continues the SQLEditor decomposition. Pulls four cohesive concerns out
of the `SQLEditorContent` composition root into co-located `use*` hooks.

## New hooks

- `useSnippetIdentity` — derives `id` / `generatedNewSnippetName` /
`isLoading` from the URL + snippet store (keeps the `[urlId]` memo dep
verbatim).
- `useEditorMount` — the editor `onMount` (scroll restore/track) + the
mount counter that lets a pre-mount diff request re-run.
- `usePrettifyQuery` — formats the editor SQL in place and writes it
back to the store.
- `useSnippetTitleGenerator` — the title-generation mutation +
`setAiTitle`.
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.

2 participants