Repository navigation
refactor(sql-editor): decompose into controller contexts + presentational components (decompose 6/6) - #47938
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe SQL editor is decomposed into controller contexts, editor and diff panels, and a layout containing toolbar, warning modal, and results views. Hook APIs are memoized, utility tabs are typed, and Explain shortcuts explicitly promote untrusted SQL before execution. ChangesSQLEditor composition
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
🎭 Playwright Test Results (next)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
d508635 to
5b7652d
Compare
…onal components (decompose 6/6) Final decomposition step. Split the SQLEditorContent monolith into a controller provider + a tree of small presentational components that consume focused contexts, eliminating prop-drilling. - SQLEditorControllers: owns all state hooks (snippet/diff/prompt/ai/execution/ explain/mount) and distributes them via four memoized contexts (useSqlEditorSnippet / useSqlEditorAssistant / useSqlEditorRun / useSqlEditorUi). Underlying hook returns are memoized so the context values stay stable across unrelated re-renders. - SQLEditorLayout: the shell — run-warning modal, toolbar, and the editor/results resizable split, each a small context consumer. - SQLEditorEditorPanel: the editor pane composed of diff view, main view, and the two ask-AI widgets. - SQLEditor: an 11-line provider composition root (was the 1056-line monolith). Safe-SQL boundary: the provider exposes only the already-safe execute pipelines plus readEditorSql (UntrustedSqlFragment). Every acceptUntrustedSql promotion happens at the user-action site (toolbar/editor/results/modal handlers and the explain shortcut handler), never in the provider — keeping promotion auditable. Also: tighten the utility-tab type to a union, refocus the editor after accepting/discarding an AI diff, and drop an unneeded exhaustive-deps disable. Behavior-preserving; the Phase-1 characterization suite stays green (11/11).
5b7652d to
a755f1f
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/components/interfaces/SQLEditor/useEditorMount.ts (1)
20-36: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid depending on the reactive
tabssnapshot here.tabs.tabsMap[tabId]is only needed whenonMountruns, so keepingtabsin the dependency array will recreate the callback on unrelated tabs updates and churnuiValuefor everyuseSqlEditorUi()consumer. Use a non-reactive snapshot getter for the lookup to keeponMountstable.🤖 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/interfaces/SQLEditor/useEditorMount.ts` around lines 20 - 36, Update onMount to retrieve tabData through the available non-reactive tabs snapshot getter instead of the reactive tabs.tabsMap reference. Remove tabs from the useCallback dependency array while preserving the existing scroll restoration behavior and stable callback identity.
🤖 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.
Nitpick comments:
In `@apps/studio/components/interfaces/SQLEditor/useEditorMount.ts`:
- Around line 20-36: Update onMount to retrieve tabData through the available
non-reactive tabs snapshot getter instead of the reactive tabs.tabsMap
reference. Remove tabs from the useCallback dependency array while preserving
the existing scroll restoration behavior and stable callback identity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 420f8643-e0a0-4485-9f21-2703209129d0
📒 Files selected for processing (11)
apps/studio/components/interfaces/SQLEditor/SQLEditor.tsxapps/studio/components/interfaces/SQLEditor/SQLEditor.types.tsapps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsxapps/studio/components/interfaces/SQLEditor/SQLEditorEditorPanel.tsxapps/studio/components/interfaces/SQLEditor/SQLEditorLayout.tsxapps/studio/components/interfaces/SQLEditor/hooks.tsapps/studio/components/interfaces/SQLEditor/useEditorMount.tsapps/studio/components/interfaces/SQLEditor/useSqlEditorAi.tsapps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.tsapps/studio/components/interfaces/SQLEditor/useSqlEditorExplain.tsapps/studio/components/interfaces/SQLEditor/useSqlEditorShortcuts.ts
onMount read tabData from the reactive tabs snapshot with tabs in its dep array, so the callback identity churned on every tab-state change. Read it non-reactively from the stable TabsStateContext proxy via valtio snapshot() instead, and drop tabs from the deps. Scroll restoration is unchanged.
awaseem
left a comment
There was a problem hiding this comment.
LGTM tested on staging and self hosted
What
Final step (6 of 6) of the
SQLEditor.tsxdecomposition. Splits the twoResizablePanelbodies out of theSQLEditorContentmonolith into presentational sub-components:SQLEditorPane— the editor panel: loading state,DiffEditor+ diff ask-AI widget,MonacoEditor+ ask-AI widget. Reads the Monaco refs (editorRef/monacoRef/diffEditorRef) fromSQLEditorContext, and receives thediff/prompt/aicontrollers plus reactive state as props.SQLEditorResults— the results panel: loading state +UtilityPanel.SQLEditorContentis now a composition root: shared-ref provider, hook composition, and the run-query warning modal.Result
SQLEditor.tsxgoes from the original 1056-line monolith down to 259 lines (≈75% reduction). The remaining size over a bare ~140-line root is the run-query warning modal, kept inline deliberately: its handlers hold theacceptUntrustedSqlpromotion, which must stay at the explicit user-action boundary in the root rather than moving into a presentational pane.Behavior-preserving
The moved JSX is byte-identical aside from prop threading. No logic, effects, dependency arrays, or
eslint-disables changed. The two render-time ref reads — the editor placeholder (!promptState.isOpen && !editorRef.current?.getValue()) and the ask-AI widget gate (editorRef.current && promptState.isOpen && !isDiffOpen) — are preserved verbatim inSQLEditorPane, which re-renders whenever theprompt/diffprops change, keeping those reads fresh (the guardrail from the plan).Verification (all green):
SQLEditor.test.tsxcharacterization suite — 11/11 passtsc --noEmit— no new errorsStack
Builds on decompose 5 (#47935). This is the last PR in the series — the decomposition is complete after this merges.
Summary by CodeRabbit