fix(sqllab): race condition when updating cursor position #30154
+58
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
#30141 resolved the initial SQLLab page loading issue, but I identified that the same race condition error occurs when the cursor moves.
The problem is that the cursorPosition should only be accessed during onLoad to set the initial cursor position, but an issue arises where the Ace Editor is re-rendered whenever the cursorPosition is changed via useQueryEditor selector. During rerendering, the Ace Editor keeps resetting the cursor position, triggering the cursorUpdate event, which in turn causes onCursorPositionChange to be called repeatedly, leading to an infinite cursor position update loop.
To resolve this, avoided accessing the cursor position in real-time from the unsaved state and limited access to the initial state only, thereby preventing the number of re-renders.
TESTING INSTRUCTIONS
Specs are added
ADDITIONAL INFORMATION