Repository navigation
feat(code-editor): degraded editor and status bar - #8867
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe PR adds long-line detection, alternate JSON formatting, degraded CodeMirror profiles, performance alerts, editor layout updates, shared Alert UI, and tests for unsafe values and edits. ChangesLong-line safety and formatting
Status alert UI
Degraded editor profiles and transitions
Editor safety validation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CodeMirror
participant CodeEditor
participant LongLineUtilities
participant EditorPerformanceAlert
CodeMirror->>CodeEditor: beforeChange event
CodeEditor->>LongLineUtilities: changeIntroducesLongLine
LongLineUtilities-->>CodeEditor: unsafe edit state
CodeEditor->>CodeEditor: apply degraded or normal profile
CodeEditor->>EditorPerformanceAlert: render current long-line mode
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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.
Pull request overview
Adds “pathological long single-line” detection to the app’s CodeMirror 5 editor to prevent UI hangs, with a degraded editor profile and an in-editor notice/toggle to allow users to opt back into full features when needed.
Changes:
- Introduces long-line detection utilities (+ unit tests) and reuses them to choose safer JSON formatting for extreme single-line payloads.
- Adds a degraded CodeEditor profile (disabling expensive editor features) plus a UI alert/toggle for enabling/disabling “full editor” mode.
- Updates CodeMirror test mocks and adds targeted CodeEditor tests covering degraded/full-mode transitions.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/bruno-app/src/utils/common/long-lines.js | New utilities to detect long single lines and predict whether an edit introduces one. |
| packages/bruno-app/src/utils/common/long-lines.spec.js | Unit tests for long-line detection helpers. |
| packages/bruno-app/src/utils/common/index.js | Uses long-line detection to switch JSON formatting strategy for pathological single-line payloads. |
| packages/bruno-app/src/utils/common/index.spec.js | Adds coverage ensuring prettifyJsonString handles pathological single-line JSON. |
| packages/bruno-app/src/components/ResponseExample/ResponseExampleRequestPane/ResponseExampleBodyMode/index.js | Reuses prettifyJsonString for prettifying example JSON (inherits long-line safety). |
| packages/bruno-app/src/components/CodeEditor/editor-profile.js | New “normal vs degraded” profile builder/applier for CodeMirror options. |
| packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js | New notice UI to inform users and allow toggling full editor mode. |
| packages/bruno-app/src/components/CodeEditor/index.js | Integrates long-line detection, degraded mode, persistence behavior changes, and notice toggle. |
| packages/bruno-app/src/components/CodeEditor/index.spec.js | Adds tests for degraded mode entry/exit and ordering of editor updates. |
| packages/bruno-app/src/components/CodeEditor/StyledWrapper.js | Layout/styling updates to support the notice stack and new editor shell structure. |
| packages/bruno-app/src/test-utils/mocks/codemirror.js | Enhances CodeMirror mock to support new editor interactions used by the tests. |
| packages/bruno-app/src/ui/Alert/index.js | New Alert UI component used for the CodeEditor performance notice. |
| packages/bruno-app/src/ui/Alert/StyledWrapper.js | Alert styling (status-based colors, layout for icon/content/actions). |
| packages/bruno-app/src/ui/Alert/Alert.stories.jsx | Storybook stories for the new Alert component. |
| packages/bruno-app/src/ui/index.js | Exposes Alert via the ui barrel export. |
Suppressed comments (1)
packages/bruno-app/src/components/CodeEditor/editor-profile.js:53
- applyEditorProfile also sets lineWrapping from props even when switching into the degraded profile. That means toggling into degraded mode won’t actually force wrapping off, which undermines the performance safety profile.
const degraded = profile === 'degraded';
const variables = getAllVariables(props.collection, props.item);
editor.setOption('lineWrapping', props.enableLineWrapping ?? true);
editor.setOption('lineNumbers', !degraded);
💡 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
🧹 Nitpick comments (5)
packages/bruno-app/src/components/CodeEditor/StyledWrapper.js (2)
51-54: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
.editor-notice-highlightlooks unused.No file in this change set applies the class.
EditorPerformanceAlertusestext-xs text-mutedinstead. Remove the rule, or apply it where the warning text needs emphasis.#!/bin/bash # Confirm the class has no consumer. rg -n 'editor-notice-highlight' packages/bruno-app/src🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/CodeEditor/StyledWrapper.js` around lines 51 - 54, Remove the unused .editor-notice-highlight rule from the StyledWrapper styles, since EditorPerformanceAlert uses text-xs text-muted and no consumer applies this class.
29-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueThis rule styles
Alertinternals from outside.
.alert-contentis an internal class ofpackages/bruno-app/src/ui/Alert/index.js.packages/bruno-app/src/ui/index.jsstates that consumers should not reach into a component's internals. Consider a prop or aclassNameonAlertinstead, so a future change to the Alert markup does not silently break this layout.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/CodeEditor/StyledWrapper.js` around lines 29 - 32, Remove the `.editor-notice-stack .alert-content` selector from `StyledWrapper` and expose the alignment through the `Alert` component’s public API, such as a supported prop or root `className`. Apply the layout styling through that API so `StyledWrapper` no longer depends on the internal `.alert-content` markup defined by `Alert`.packages/bruno-app/src/components/CodeEditor/index.js (1)
549-565: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDouble gate on the notice.
showEditorNoticealready equalsthis.state.longLineDetected, andEditorPerformanceAlertreturnsnullfor a falsylongLineDetected. Keep one gate. Rendering<EditorPerformanceAlert>unconditionally and letting it decide is the smaller surface.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/CodeEditor/index.js` around lines 549 - 565, Remove the redundant showEditorNotice conditional around EditorPerformanceAlert in the CodeEditor render flow, and render the component unconditionally while preserving its existing longLineDetected, longLineMode, and handler props so the component continues deciding whether to return null.packages/bruno-app/src/test-utils/mocks/codemirror.js (1)
8-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMock fidelity:
getLineignores the line index, andgetInputFieldreturns a new element each call.
getLinereturns the whole document for any line, andgetRangeignoresfrom._onBeforeChangeinCodeEditorpasses a real line index tochangeIntroducesLongLine, so multi-line prefix/suffix logic cannot be exercised and a regression there would pass.getInputFieldcreates a freshtextareaon every call, so the element thatcomponentDidMountadds themousetrapclass to is not the element any later call receives.♻️ Proposed change
- getRange: jest.fn((from, to) => editor._currentValue?.slice(0, to.ch) || ''), + getRange: jest.fn((from, to) => (editor._currentValue || '').split('\n')[from.line]?.slice(from.ch, to.ch) || ''), getValue: jest.fn(() => editor._currentValue), setValue: jest.fn(function (val) { editor._currentValue = val; }), - getLine: jest.fn(() => editor._currentValue || ''), + getLine: jest.fn((line) => (editor._currentValue || '').split('\n')[line ?? 0] || ''),- getInputField: jest.fn(() => document.createElement('textarea')), + _inputField: document.createElement('textarea'), + getInputField: jest.fn(() => editor._inputField),Also applies to: 23-23
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/test-utils/mocks/codemirror.js` around lines 8 - 13, Update the CodeMirror mock’s getLine and getRange implementations to honor line boundaries and the supplied from/to positions, matching real multi-line editor behavior for CodeEditor._onBeforeChange and changeIntroducesLongLine. Make getInputField return one persistent textarea instance so classes added during componentDidMount remain visible on subsequent calls. Preserve existing mock APIs and return behavior for valid requests.packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js (1)
11-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the duplicate
longLineDetectedcheck.Line 11 already returns
null. The conditional at Line 17 is always true. Also importAlertfrom the barrel, becausepackages/bruno-app/src/ui/index.jsstates that deep paths are discouraged.♻️ Proposed change
-import Alert from 'ui/Alert'; +import { Alert } from 'ui';return ( <div className="editor-notice-stack"> - {longLineDetected && ( - <Alert + <Alert(Then drop the matching closing
)}.)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js` around lines 11 - 17, In the EditorPerformanceAlert render flow, remove the redundant longLineDetected conditional and its matching closing syntax because the early return already guarantees it is true. Update the Alert import to use the barrel export from the ui index instead of a deep path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-app/src/components/CodeEditor/editor-profile.js`:
- Around line 20-21: Disable line wrapping whenever degraded mode is active in
both buildCodeMirrorOptions and applyEditorProfile. Update
packages/bruno-app/src/components/CodeEditor/editor-profile.js lines 20-21 and
52 so degraded takes precedence over props.enableLineWrapping, ensuring
transitions into degraded mode also turn wrapping off.
In `@packages/bruno-app/src/components/CodeEditor/index.js`:
- Around line 616-623: Update _onBeforeChange so forced degradation only occurs
when the edit creates a long line from a previously non-long line. Check the
affected line’s pre-change length before resetting longLineOverride and calling
_applyLongLineMode, while preserving the existing behavior for genuinely newly
introduced long lines and allowing edits to lines already over the limit.
In `@packages/bruno-app/src/components/CodeEditor/index.spec.js`:
- Around line 98-99: Update the test around changeHandler in index.spec.js so
the long-line mutation is not an assertion-free action: either add expectations
verifying the degraded-mode notice remains shown and lint remains false after
act(() => changeHandler()), or remove the _currentValue mutation and handler
invocation if that behavior is not being tested.
In `@packages/bruno-app/src/ui/Alert/StyledWrapper.js`:
- Around line 4-17: Update getStatusTokens to use distinct theme
status-background tokens for danger, warning, success, and info instead of
returning lighter(theme.brand) for every branch. Inspect both light and dark
theme definitions for the established token names, then map each status
consistently and verify the resulting backgrounds maintain readable contrast
with theme.text.
---
Nitpick comments:
In `@packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js`:
- Around line 11-17: In the EditorPerformanceAlert render flow, remove the
redundant longLineDetected conditional and its matching closing syntax because
the early return already guarantees it is true. Update the Alert import to use
the barrel export from the ui index instead of a deep path.
In `@packages/bruno-app/src/components/CodeEditor/index.js`:
- Around line 549-565: Remove the redundant showEditorNotice conditional around
EditorPerformanceAlert in the CodeEditor render flow, and render the component
unconditionally while preserving its existing longLineDetected, longLineMode,
and handler props so the component continues deciding whether to return null.
In `@packages/bruno-app/src/components/CodeEditor/StyledWrapper.js`:
- Around line 51-54: Remove the unused .editor-notice-highlight rule from the
StyledWrapper styles, since EditorPerformanceAlert uses text-xs text-muted and
no consumer applies this class.
- Around line 29-32: Remove the `.editor-notice-stack .alert-content` selector
from `StyledWrapper` and expose the alignment through the `Alert` component’s
public API, such as a supported prop or root `className`. Apply the layout
styling through that API so `StyledWrapper` no longer depends on the internal
`.alert-content` markup defined by `Alert`.
In `@packages/bruno-app/src/test-utils/mocks/codemirror.js`:
- Around line 8-13: Update the CodeMirror mock’s getLine and getRange
implementations to honor line boundaries and the supplied from/to positions,
matching real multi-line editor behavior for CodeEditor._onBeforeChange and
changeIntroducesLongLine. Make getInputField return one persistent textarea
instance so classes added during componentDidMount remain visible on subsequent
calls. Preserve existing mock APIs and return behavior for valid requests.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8846a99e-9380-4088-94da-f1ee6d4d710a
📒 Files selected for processing (15)
packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.jspackages/bruno-app/src/components/CodeEditor/StyledWrapper.jspackages/bruno-app/src/components/CodeEditor/editor-profile.jspackages/bruno-app/src/components/CodeEditor/index.jspackages/bruno-app/src/components/CodeEditor/index.spec.jspackages/bruno-app/src/components/ResponseExample/ResponseExampleRequestPane/ResponseExampleBodyMode/index.jspackages/bruno-app/src/test-utils/mocks/codemirror.jspackages/bruno-app/src/ui/Alert/Alert.stories.jsxpackages/bruno-app/src/ui/Alert/StyledWrapper.jspackages/bruno-app/src/ui/Alert/index.jspackages/bruno-app/src/ui/index.jspackages/bruno-app/src/utils/common/index.jspackages/bruno-app/src/utils/common/index.spec.jspackages/bruno-app/src/utils/common/long-lines.jspackages/bruno-app/src/utils/common/long-lines.spec.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js (1)
11-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the redundant
longLineDetectedguard.Line 11 already returns
nullwhenlongLineDetectedis falsy. The check at line 17 can never be false.CodeEditor.renderalso guards on the same flag before mounting this component, so the alert is guarded three times. Drop the inner check and the wrapper<div>becomes the only remaining shell. Also remove the blank line at line 34.♻️ Proposed simplification
return ( <div className="editor-notice-stack"> - {longLineDetected && ( - <Alert - status="info" - actions={( - <ToggleSwitch - title="Enable all editor features" - isOn={!longLineMode} - size="2xs" - handleToggle={() => { - if (longLineMode) { - return onEnableFullMode(); - } - return onDisableFullMode(); - }} - /> - )} - > - - <div className="flex flex-col gap-2"> - {longLineMode - ? 'The length of the content may impact performance. Highlighting, linting, and editor helpers are disabled.' - : 'Full editor enabled for this content - this may impact app performance.'} - - <span className="text-xs text-muted">You can {longLineMode ? 'enable' : 'disable'} the full editor with the toggle</span> - </div> - </Alert> - )} + <Alert + status="info" + actions={( + <ToggleSwitch + title="Enable all editor features" + isOn={!longLineMode} + size="2xs" + handleToggle={() => (longLineMode ? onEnableFullMode() : onDisableFullMode())} + /> + )} + > + <div className="flex flex-col gap-2"> + {longLineMode + ? 'The length of the content may impact performance. Highlighting, linting, and editor helpers are disabled.' + : 'Full editor enabled for this content - this may impact app performance.'} + <span className="text-xs text-muted">You can {longLineMode ? 'enable' : 'disable'} the full editor with the toggle</span> + </div> + </Alert> </div> );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js` around lines 11 - 44, Remove the redundant longLineDetected conditional inside the returned JSX in EditorPerformanceAlert, since the earlier guard already handles the false case. Keep the editor-notice-stack wrapper as the remaining shell, and remove the extra blank line before the alert content.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js`:
- Around line 11-44: Remove the redundant longLineDetected conditional inside
the returned JSX in EditorPerformanceAlert, since the earlier guard already
handles the false case. Keep the editor-notice-stack wrapper as the remaining
shell, and remove the extra blank line before the alert content.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d2d424e2-99dc-4477-a983-956773ddf38b
📒 Files selected for processing (15)
packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.jspackages/bruno-app/src/components/CodeEditor/StyledWrapper.jspackages/bruno-app/src/components/CodeEditor/editor-profile.jspackages/bruno-app/src/components/CodeEditor/index.jspackages/bruno-app/src/components/CodeEditor/index.spec.jspackages/bruno-app/src/components/ResponseExample/ResponseExampleRequestPane/ResponseExampleBodyMode/index.jspackages/bruno-app/src/test-utils/mocks/codemirror.jspackages/bruno-app/src/ui/Alert/Alert.stories.jsxpackages/bruno-app/src/ui/Alert/StyledWrapper.jspackages/bruno-app/src/ui/Alert/index.jspackages/bruno-app/src/ui/index.jspackages/bruno-app/src/utils/common/index.jspackages/bruno-app/src/utils/common/index.spec.jspackages/bruno-app/src/utils/common/long-lines.jspackages/bruno-app/src/utils/common/long-lines.spec.js
🚧 Files skipped from review as they are similar to previous changes (13)
- packages/bruno-app/src/utils/common/index.spec.js
- packages/bruno-app/src/ui/Alert/StyledWrapper.js
- packages/bruno-app/src/ui/index.js
- packages/bruno-app/src/utils/common/long-lines.spec.js
- packages/bruno-app/src/ui/Alert/Alert.stories.jsx
- packages/bruno-app/src/components/CodeEditor/StyledWrapper.js
- packages/bruno-app/src/ui/Alert/index.js
- packages/bruno-app/src/test-utils/mocks/codemirror.js
- packages/bruno-app/src/utils/common/long-lines.js
- packages/bruno-app/src/components/CodeEditor/editor-profile.js
- packages/bruno-app/src/utils/common/index.js
- packages/bruno-app/src/components/CodeEditor/index.spec.js
- packages/bruno-app/src/components/ResponseExample/ResponseExampleRequestPane/ResponseExampleBodyMode/index.js
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.js`:
- Line 38: Update the full-mode alert message in EditorPerformanceAlert to read
grammatically: state that all editor features are enabled for this content, then
start the performance warning as a separate sentence.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 71e04285-abf5-4cbe-b80d-0a774a039089
📒 Files selected for processing (3)
packages/bruno-app/src/components/CodeEditor/EditorPerformanceAlert.jspackages/bruno-app/src/components/CodeEditor/StyledWrapper.jspackages/bruno-app/src/ui/Alert/StyledWrapper.js
💤 Files with no reviewable changes (1)
- packages/bruno-app/src/components/CodeEditor/StyledWrapper.js
96096ba to
f0056a2
Compare
BRU-4054
Description
Problem
Codemirror 5 doesn't do horizontal viewport based virtualisation, which means that a single long line of ~5MB of data with all the basic codemirror addons go through the whole 5MB in a single go instead of doing it per line (which is easier and less memory hungry).
On powerful systems, this adds a slight lag to the window, on most other system the app becomes unusable.
Screenshots
What the status bar looks like
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