-
Notifications
You must be signed in to change notification settings - Fork 17
fix: monaco-ghost infinite loop #3021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an infinite loop issue in the Monaco editor caused by the useSavedQueries hook continuously returning new array references. The fix involves two key changes:
- Memoizes the filtered saved queries array to prevent unnecessary re-renders
- Replaces the
useSavedQuerieshook with directuseSettingusage inuseCodeAssistHelpersto avoid unnecessary filtering
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/containers/Tenant/Query/utils/useSavedQueries.tsx | Added React.useMemo to prevent returning new array references on every render when filtering saved queries |
| src/containers/Tenant/Query/QueryEditor/helpers.ts | Changed from using useSavedQueries hook to directly accessing saved queries via useSetting, bypassing user filters for code assist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Closes #2007
Closes #3019
The first problem is that useSavedQueries for present filter always returned new array as .filter returns new array
Solution: use memo in useSavedQueries
The second problem is that we used useSavedQueries in in useCodeAssistHelpers - it should send saved queries independently from any user filters
Solution: use savedQueries from settings and disregard filters
Greptile Overview
Updated On: 2025-10-28 12:13:26 UTC
Greptile Summary
This PR fixes an infinite loop in the Monaco editor code assist feature caused by unstable array references in dependency chains.
Key Changes:
useSavedQueries()hook with directuseSetting()call to bypass filter state dependencyReact.useMemoto memoize filtered array results, ensuring stable references when dependencies haven't changedRoot Cause:
The
useSavedQuerieshook called.filter()on every render, creating new array references even with identical content. This cascaded throughuserQueriesmemo →prepareUserQueriesCachecallback →monacoGhostConfigmemo, triggering theuseEffectinYqlEditor.tsx:90repeatedly.Solution:
Two-pronged approach: (1) Code assist no longer needs filtered queries - it should send all saved queries for context, so switching to
useSettingeliminates the filter dependency entirely. (2) For UI components that still useuseSavedQueries, memoization prevents unnecessary array recreation.Confidence Score: 5/5
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant YqlEditor participant useCodeAssistHelpers participant useSavedQueries participant Redux as Redux Store participant Monaco as Monaco Ghost Note over YqlEditor,Monaco: Before Fix (Infinite Loop) YqlEditor->>useCodeAssistHelpers: Call hook useCodeAssistHelpers->>useSavedQueries: Get filtered queries useSavedQueries->>Redux: Get filter state useSavedQueries->>useSavedQueries: .filter() returns NEW array useSavedQueries-->>useCodeAssistHelpers: New array reference useCodeAssistHelpers->>useCodeAssistHelpers: userQueries memo recomputes useCodeAssistHelpers->>useCodeAssistHelpers: monacoGhostConfig memo recomputes useCodeAssistHelpers-->>YqlEditor: New config reference YqlEditor->>YqlEditor: useEffect triggers (dependency changed) YqlEditor->>Monaco: Register new config Note over YqlEditor: Cycle repeats infinitely Note over YqlEditor,Monaco: After Fix (Stable) YqlEditor->>useCodeAssistHelpers: Call hook useCodeAssistHelpers->>useCodeAssistHelpers: useSetting (no filter dependency) useCodeAssistHelpers->>useCodeAssistHelpers: userQueries memo (stable array) useCodeAssistHelpers->>useCodeAssistHelpers: monacoGhostConfig memo (stable) useCodeAssistHelpers-->>YqlEditor: Same config reference YqlEditor->>YqlEditor: useEffect stable (no re-trigger) YqlEditor->>Monaco: Config remains registered Note over YqlEditor: No infinite loop Note over useSavedQueries: useSavedQueries still used in UI components useSavedQueries->>Redux: Get filter state useSavedQueries->>useSavedQueries: React.useMemo prevents NEW array on same deps useSavedQueries-->>YqlEditor: Stable filtered array for UICI Results
Test Status:⚠️ FLAKY
📊 Full Report
Test Changes Summary ⏭️2
⏭️ Skipped Tests (2)
Bundle Size: ✅
Current: 47.07 MB | Main: 47.07 MB
Diff: +0.42 KB (0.00%)
✅ Bundle size unchanged.
ℹ️ CI Information