Repository navigation
refactor(sql-editor): own shared editor refs in SQLEditorContext (decompose 3/N) - #47837
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe SQL editor now uses ChangesSQL editor context refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
6418e82 to
1971ee5
Compare
| /** | ||
| * Dependency-injection channel for the SQL editor's mutable Monaco state. | ||
| * | ||
| * It owns the shared editor refs and the imperative helpers that read/write |
| /** Refocus the editor iff a run-refocus was requested, then clear the flag. */ | ||
| refocusEditorAfterRunIfNeeded: () => void | ||
| /** | ||
| * Resolve the SQL to act on from the editor (selection → full value → |
There was a problem hiding this comment.
no need for the comment here either
Introduces SQLEditorContext (provider + useSQLEditorContext guard hook) that owns the shared Monaco refs (editor/monaco/diff/scrollTop), the run-refocus flag, and the imperative highlight decorations, plus the stable helpers that read/write them: refocusEditor, clearPendingRunRefocus, markRefocusAfterRun, refocusEditorAfterRunIfNeeded, getEditorSql, clearHighlights, applyErrorHighlight. SQLEditor is split into <SQLEditorProvider><SQLEditorContent/></SQLEditorProvider>; the body now reads refs/helpers from context instead of local useRef/useCallback. lineHighlights moves from React state to a ref inside the provider (decorations are only manipulated imperatively). The context value holds only stable identities, so the provider never re-renders consumers. No behavior change: characterization suite stays green; useEffectEvent/drainDiffRequest dep array and all eslint-disabled dep arrays preserved. PR 3/N of the SQLEditor decomposition stack.
1971ee5 to
7667bfb
Compare
Braintrust eval report
|
…ompose 3/N) (#47837) ## Summary PR **3** in the SQLEditor decomposition stack. The keystone structural step: introduce a context provider that owns the shared, mutable Monaco state, so later PRs can extract logic hooks and presentational panes without threading the same three refs through every signature. Behavior-preserving — the characterization suite (merged in PR 1) stays green with identical assertions. ## What changed New `SQLEditorContext.tsx`: - `SQLEditorProvider` owns the shared refs (`editorRef`, `monacoRef`, `diffEditorRef`, `scrollTopRef`), the run-refocus flag, and the error-highlight decorations. - `useSQLEditorContext()` guard hook (React 19 `use()`), mirroring the canonical `PoliciesDataContext` pattern. - Stable helpers: `refocusEditor`, `clearPendingRunRefocus`, `markRefocusAfterRun`, `refocusEditorAfterRunIfNeeded`, `getEditorSql`, `clearHighlights`, `applyErrorHighlight`. `SQLEditor.tsx`: - Split into `<SQLEditorProvider><SQLEditorContent/></SQLEditorProvider>`. - `SQLEditorContent` reads refs/helpers from context instead of local `useRef`/`useCallback`. - `lineHighlights` moves from React state to a ref inside the provider (decorations are purely imperative; nothing renders off them). This also removes the stale-closure hazard the old `executeQuery` dep-array omission worked around. The context value holds only stable identities (refs + `useCallback`s, memoized once), so the provider never re-renders its consumers — it's a dependency-injection channel, not reactive state. ## Verification - `vitest` — 156 pass (characterization + utils), assertions unchanged - `pnpm --filter studio typecheck` — clean for all SQL editor files (the two `@sentry/tanstackstart-react` errors are a pre-existing local-install gap on master, unrelated) - `eslint` — 0 errors - Equivalence: single `useEffectEvent`, `drainDiffRequest` driving-effect deps `[diffRequest.pending, editorMountCount]` byte-identical, all 8 `eslint-disable` dep arrays preserved <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved SQL editor focus restoration after running or explaining queries. * Centralized run/explain highlighting so errors are highlighted consistently and old highlights are reliably cleared. * Ensured the SQL snippet used for run/explain is derived consistently from the current editor state. * **Refactor** * Restructured the SQL editor to use a shared internal context for editor UI, refs, and imperative highlight/focus helpers, keeping the external editor interface unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
PR 3 in the SQLEditor decomposition stack. The keystone structural step: introduce a context provider that owns the shared, mutable Monaco state, so later PRs can extract logic hooks and presentational panes without threading the same three refs through every signature.
Behavior-preserving — the characterization suite (merged in PR 1) stays green with identical assertions.
What changed
New
SQLEditorContext.tsx:SQLEditorProviderowns the shared refs (editorRef,monacoRef,diffEditorRef,scrollTopRef), the run-refocus flag, and the error-highlight decorations.useSQLEditorContext()guard hook (React 19use()), mirroring the canonicalPoliciesDataContextpattern.refocusEditor,clearPendingRunRefocus,markRefocusAfterRun,refocusEditorAfterRunIfNeeded,getEditorSql,clearHighlights,applyErrorHighlight.SQLEditor.tsx:<SQLEditorProvider><SQLEditorContent/></SQLEditorProvider>.SQLEditorContentreads refs/helpers from context instead of localuseRef/useCallback.lineHighlightsmoves from React state to a ref inside the provider (decorations are purely imperative; nothing renders off them). This also removes the stale-closure hazard the oldexecuteQuerydep-array omission worked around.The context value holds only stable identities (refs +
useCallbacks, memoized once), so the provider never re-renders its consumers — it's a dependency-injection channel, not reactive state.Verification
vitest— 156 pass (characterization + utils), assertions unchangedpnpm --filter studio typecheck— clean for all SQL editor files (the two@sentry/tanstackstart-reacterrors are a pre-existing local-install gap on master, unrelated)eslint— 0 errorsuseEffectEvent,drainDiffRequestdriving-effect deps[diffRequest.pending, editorMountCount]byte-identical, all 8eslint-disabledep arrays preservedSummary by CodeRabbit