Repository navigation
fix: monaco flicker pr test - #344
Conversation
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🟠 MajorStale closure risk when model changes after prop updates.
The
setContextForModelfunction captures prop values (connector,tableSchemas, etc.) at mount time. If props change after mount and then thepathchanges (triggeringonDidChangeModel), the new model receives stale context from the initial closure rather than the current prop values.Sequence demonstrating the issue:
- Mount captures
connector = C1connectorprop updates toC2→useEffectupdates current modelpathchanges →onDidChangeModelfires → new model getsC1(stale)Consider using a ref to track the latest prop values so
onDidChangeModelalways 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); + };
Signed-off-by: bdjulbic <[email protected]>
Summary by CodeRabbit
New Features
Bug Fixes