Repository navigation
fix: improve value handling in editor components - #7098
Conversation
WalkthroughEditors now use focus-aware value synchronization: on incoming prop changes they compare editor content and focus, deferring setValue when the editor is focused and user edits differ, otherwise updating cached value, setting the editor value, and restoring the cursor. (49 words) Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/MultiLineEditor/index.js (1)
153-155:⚠️ Potential issue | 🟡 MinorDuplicate
readOnlycheck.
readOnlyprop change is handled twice — lines 153–155 and lines 174–176. The second one also adds|| falsewhich differs from the first. Pick one and remove the other.Proposed fix — remove the duplicate
- if (this.props.readOnly !== prevProps.readOnly && this.editor) { - this.editor.setOption('readOnly', this.props.readOnly || false); - }Also applies to: 174-176
🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/RequestPane/QueryEditor/index.js`:
- Around line 159-166: The editor updates the value in the else branch (when
!hasFocus) but fails to preserve the cursor/selection, causing jumps on external
updates; modify the else branch around this.editor.setValue(nextValue) to
capture the current cursor/selection position (using this.editor's
cursor/selection APIs), call setValue(nextValue), then restore the previously
captured cursor/selection so the caret is preserved; this change should be
applied to the component code that uses this.props.value, this.editor, and
this.cachedValue.
There was a problem hiding this comment.
Pull request overview
This PR aims to make CodeMirror-based editor components handle incoming value updates more safely/consistently (notably around null/undefined), while attempting to avoid overwriting the editor content during active user focus.
Changes:
- Normalize incoming
valueprops to safe string defaults (e.g.,value ?? '',String(value ?? '')) before applying to editors. - Add focus-aware logic intended to prevent
setValue()from running while the editor has focus.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/bruno-app/src/components/SingleLineEditor/index.js | Adds focus-aware prop-to-editor value reconciliation and normalizes value to a string. |
| packages/bruno-app/src/components/RequestPane/QueryEditor/index.js | Normalizes value updates and adds focus-aware skip logic for setValue(). |
| packages/bruno-app/src/components/MultiLineEditor/index.js | Normalizes value updates and adds focus-aware skip logic for setValue(). |
| packages/bruno-app/src/components/CodeEditor/index.js | Normalizes value updates and adds focus-aware skip logic while preserving cursor on updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/CodeEditor/index.js`:
- Around line 236-246: The inline comment uses "//TODO:" which fails the linter;
update the comment in the CodeEditor component to use proper spacing "// TODO:"
and keep the rest of the focus-aware sync block intact (the block around
this.props.value handling and calls to this.editor.getValue(),
this.editor.hasFocus?.(), this.editor.setValue(), this.editor.setCursor(), and
this.cachedValue assignment).
In `@packages/bruno-app/src/components/MultiLineEditor/index.js`:
- Around line 157-167: Update the inline TODO comment above the logic that uses
this.editor, cachedValue, getValue, hasFocus, getCursor, setValue and setCursor
to match the project's comment spacing style (e.g., change "//TODO:" to "//
TODO:" and mirror the spacing/format used in CodeEditor and SingleLineEditor);
leave the surrounding logic intact.
In `@packages/bruno-app/src/components/RequestPane/QueryEditor/index.js`:
- Line 159: Fix the linting error by normalizing the inline comment spacing:
change the comment that currently begins "//TODO: temporary fix for keeping
cursor state when auto save and new line insertion collide PR#7098" to use the
linter-preferred spacing and style (e.g., "// TODO: temporary fix for keeping
cursor state when auto save and new line insertion collide PR `#7098`"). Update
that exact comment text so it includes the required space after "//" and any
spacing around "PR `#7098`" if your linter enforces it.
In `@packages/bruno-app/src/components/SingleLineEditor/index.js`:
- Line 172: The inline comment in SingleLineEditor (the TODO comment "//TODO:
temporary fix for keeping cursor state when auto save and new line insertion
collide PR#7098") violates spacing lint rules; update it to follow project
comment style by inserting a space after the // and after the TODO keyword
(e.g., "// TODO: temporary fix...") and ensure consistent spacing around
"PR#7098" (e.g., "PR `#7098`" or follow repo convention) so it passes the linter.
Description
Temporary fix for preserving cursor positions lost during editor re-renders. This is not an ideal long-term solution, but it avoids the overhead of storing the entire CodeMirror operation log. It specifically addresses cursor displacement that occurs when auto-save and new-line shortcuts are pressed simultaneously, causing a re-render that resets the cursor position.
A proper solution is to add stable ids to items and collections so a combination can be used for editors and other things to avoid the re-render from happening in the first place.
JIRA
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit