-
Notifications
You must be signed in to change notification settings - Fork 75
[LG-5930] fix(CodeEditor): prevent tooltip range errors #3486
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
base: main
Are you sure you want to change the base?
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 a critical bug in the CodeEditor component where tooltips configured for specific line numbers cause RangeError exceptions when the document content changes (lines added/removed). The errors occur because the tooltip extension attempts to access line numbers that no longer exist in the updated document, eventually making the editor unresponsive.
Changes:
- Added bounds checking to filter out tooltips referencing invalid line numbers
- Added clamping logic to ensure column and length values stay within line boundaries
- Added comprehensive test coverage for the new validation logic
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/code-editor/src/CodeEditor/hooks/extensions/useTooltipExtension.ts | Added filtering to exclude tooltips with invalid line numbers and clamping for column/length values to prevent RangeErrors |
| packages/code-editor/src/CodeEditor/hooks/extensions/useTooltipExtension.spec.ts | Added test utilities and three test cases covering out-of-bounds line filtering, column/length clamping, and error prevention |
| expect(diagnostics[1].to).toBe(13); | ||
| }); | ||
|
|
||
| test('does not throw when tooltips reference lines that no longer exist after document changes', () => { |
Copilot
AI
Jan 27, 2026
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.
The test name is verbose and redundant. Consider renaming to 'returns empty diagnostics when tooltips reference non-existent lines' which more clearly describes the expected behavior being tested.
| test('does not throw when tooltips reference lines that no longer exist after document changes', () => { | |
| test('returns empty diagnostics when tooltips reference non-existent lines', () => { |
|
Size Change: +118 B (+0.01%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
|
Coverage after merging LG-5930/editor-tooltip-bug into main will be
Coverage Report for Changed Files
|
|||||||||||||||||||
* feat(tooltip-extension): enhance tooltip bounds checking and diagnostics handling * Lint fix
✍️ Proposed changes
Summary
The CodeEditor component throws uncaught RangeError exceptions when the document content changes (lines added/removed) while tooltips are configured. This causes the editor to become unresponsive after adding enough lines, preventing further editing or line deletion.
🎟 Jira ticket: Name of ticket
Steps to Reproduce
Expected Behavior
The editor should handle document changes gracefully, ignoring or adjusting tooltips that reference lines that no longer exist.
Actual Behavior
The editor throws repeated RangeError exceptions:
After enough errors accumulate, the editor becomes unresponsive and editing is blocked.
Root Cause
The linter callback in
useTooltipExtensionaccesses line numbers from the tooltips prop without validating they exist in the current document. When CodeMirror re-runs the linter after document changes, it calls doc.line with stale line numbers that are now out of bounds.Fix
✅ Checklist
pnpm changesetand documented my changes🧪 How to test changes