Skip to content

fix: monaco flicker pr test - #344

Merged
bdjulbic merged 5 commits into
mainfrom
fix/monaco-flicker-pr-test
Mar 6, 2026
Merged

bdjulbic merged 5 commits into
mainfrom
fix/monaco-flicker-pr-test

Conversation

@bdjulbic

@bdjulbic bdjulbic commented Feb 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Remove text flicker when switching tabs
    • Editor state (cursor position, scroll location) is now preserved per tab when switching between queries.
  • Bug Fixes

    • Improved accuracy of SQL completion suggestions by maintaining synchronized context with the active editor model.
    • Enhanced cleanup behavior when closing editors.

@coderabbitai

coderabbitai Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes implement per-model context management in SqlMonacoEditor and configure tab-specific behavior in QueryEditorPanelEditor. A new helper function synchronizes completion context with Monaco model changes, and QueryEditorPanelEditor now configures the editor with path, view state preservation, and model retention props.

Changes

Cohort / File(s) Summary
SqlMonacoEditor Context Synchronization
packages/sql-editor/src/SqlMonacoEditor.tsx
Introduces setContextForModel helper to manage per-model completion context initialization and updates. Subscribes to model changes via onDidChangeModel to keep context synchronized when Monaco swaps models. Refactors disposal logic to consistently detach model context on editor disposal.
QueryEditorPanelEditor Configuration
packages/sql-editor/src/components/QueryEditorPanelEditor.tsx
Adds three props to SqlMonacoEditor: path (sqlrooms://query/{queryId}.sql), saveViewState (for per-tab cursor/scroll preservation), and keepCurrentModel (to retain previous editor model across path switches).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit's completion quest
Models waltz, but context stays,
Helper functions light the ways,
Per-tab views preserved with care,
Monaco models match, fair and square! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: monaco flicker pr test [DRAFT]' is vague and uses non-descriptive terms like 'pr test' that don't clearly convey the main technical change being addressed. Revise the title to be more specific about the actual fix, such as 'fix: keep SQL completion context synced with Monaco model changes' or similar wording that describes the core improvement.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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
  • Commit unit tests in branch fix/monaco-flicker-pr-test

Tip

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


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 and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/sql-editor/src/SqlMonacoEditor.tsx (1)

316-336: 🛠️ Refactor suggestion | 🟠 Major

Stale closure risk when model changes after prop updates.

The setContextForModel function captures prop values (connector, tableSchemas, etc.) at mount time. If props change after mount and then the path changes (triggering onDidChangeModel), the new model receives stale context from the initial closure rather than the current prop values.

Sequence demonstrating the issue:

  1. Mount captures connector = C1
  2. connector prop updates to C2 → useEffect updates current model
  3. path changes → onDidChangeModel fires → new model gets C1 (stale)

Consider using a ref to track the latest prop values so onDidChangeModel always sets current context:

Proposed fix using a ref for latest props
 export const SqlMonacoEditor: React.FC<SqlMonacoEditorProps> = ({
   connector,
   customKeywords = [],
   customFunctions = [],
   tableSchemas = [],
   getLatestSchemas,
   onMount,
   className,
   options,
   ...restProps
 }) => {
   const modelRef = useRef<any>(null);
+  const latestPropsRef = useRef({
+    connector,
+    tableSchemas,
+    getLatestSchemas,
+    customKeywords,
+    customFunctions,
+  });
+
+  // Keep ref in sync with latest props
+  useEffect(() => {
+    latestPropsRef.current = {
+      connector,
+      tableSchemas,
+      getLatestSchemas,
+      customKeywords,
+      customFunctions,
+    };
+  }, [connector, tableSchemas, getLatestSchemas, customKeywords, customFunctions]);

Then inside handleEditorDidMount:

-      const setContextForModel = (model: any) => {
-        if (!model) return;
-        modelRef.current = model;
-        sqlCompletionContextByModel.set(model, {
-          connector,
-          tableSchemas,
-          getLatestSchemas,
-          customKeywords,
-          customFunctions,
-        });
-      };
+      const setContextForModel = (model: any) => {
+        if (!model) return;
+        modelRef.current = model;
+        sqlCompletionContextByModel.set(model, latestPropsRef.current);
+      };

@bdjulbic bdjulbic changed the title Fix/monaco flicker pr test [DRAFT] fix: monaco flicker pr test [DRAFT] Feb 11, 2026
@bdjulbic bdjulbic changed the title fix: monaco flicker pr test [DRAFT] fix: monaco flicker pr test Mar 5, 2026
@bdjulbic
bdjulbic merged commit 275084e into main Mar 6, 2026
4 checks passed
@bdjulbic
bdjulbic deleted the fix/monaco-flicker-pr-test branch March 6, 2026 12:41
@coderabbitai coderabbitai Bot mentioned this pull request Mar 9, 2026
bdjulbic added a commit that referenced this pull request Mar 16, 2026
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