Skip to content

fix: refresh code editor and query editor on resize#7889

Open
prateek-bruno wants to merge 1 commit intousebruno:mainfrom
prateek-bruno:bugfix/artifacts-in-file-editor
Open

fix: refresh code editor and query editor on resize#7889
prateek-bruno wants to merge 1 commit intousebruno:mainfrom
prateek-bruno:bugfix/artifacts-in-file-editor

Conversation

@prateek-bruno
Copy link
Copy Markdown
Collaborator

@prateek-bruno prateek-bruno commented Apr 29, 2026

Description

Jira

CodeEditor remains in a stale state when the resize happens due to the layout change horizontally <-> vertical.

This is because CodeEditor auto-refreshes only when window resize happens and not actually when the view switch resize happens to the size.

This PR adds a resize listener to CodeEditor and refreshes it on resize.

Before:

Screen.Recording.2026-04-29.at.5.55.27.PM.mov

After:

Screen.Recording.2026-04-29.at.5.56.21.PM.mov

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Summary by CodeRabbit

  • Bug Fixes

    • Code editor now reliably refreshes when its container or layout changes, preventing stale layouts and improving responsiveness during resizes and layout toggles.
  • Tests

    • Added end-to-end test coverage verifying the editor remeasures and renders correctly after layout changes, checking rendered line count and height calculations to prevent visual regressions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a ResizeObserver to the CodeEditor component that schedules an editor refresh via requestAnimationFrame on container size changes and cancels pending frames. The observer is attached on mount and disconnected on unmount. Adds a Playwright E2E test verifying CodeMirror remeasurement after layout toggles.

Changes

CodeEditor Resize + Test

Layer / File(s) Summary
Data / State Init
packages/bruno-app/src/components/CodeEditor/index.js
Introduces this.resizeRefreshFrameId = null in the component constructor to track scheduled RAF callbacks.
Mount-time wiring
packages/bruno-app/src/components/CodeEditor/index.js
Calls this.setupResizeObserver() from componentDidMount after editor setup to begin observing the container.
Runtime handler
packages/bruno-app/src/components/CodeEditor/index.js
Adds setupResizeObserver which creates a ResizeObserver on this._node, cancels any existing RAF, schedules a fresh requestAnimationFrame that calls this.editor?.refresh(), and clears the id after execution.
Unmount cleanup
packages/bruno-app/src/components/CodeEditor/index.js
On componentWillUnmount disconnects the ResizeObserver and cancels any pending RAF stored in resizeRefreshFrameId.
End-to-end test
tests/request/editor-layout/code-editor-layout-resize.spec.ts
New Playwright test that injects a large JSON into the request-body CodeMirror, toggles response layout (vertical↔horizontal↔vertical), waits via RAF cycles, and asserts wrapper/lines heights and rendered line count indicate correct remeasurement.

Sequence Diagram

sequenceDiagram
    actor DOM as DOM Container
    participant RO as ResizeObserver
    participant CE as CodeEditor
    participant RAF as RequestAnimationFrame
    participant CM as CodeMirror

    DOM->>RO: element resize
    RO->>CE: invoke callback
    CE->>CE: cancel pending RAF (if any)
    CE->>RAF: requestAnimationFrame(callback)
    RAF->>CE: execute callback
    CE->>CM: editor.refresh()
    CM->>CM: remeasure & redraw
    CE->>CE: clear resizeRefreshFrameId
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • sid-bruno
  • naman-bruno
  • bijin-bruno

Poem

🪟 When panes expand and windows sway,
An observer wakes to save the day.
A frame is queued, the editor sings,
Lines realign on freshened wings. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: adding ResizeObserver-driven refresh handling to the CodeEditor component when layout resizes occur.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/bruno-app/src/components/CodeEditor/index.spec.js (1)

14-51: Add one cleanup-focused test for the new resize flow.

This test covers the resize happy path well, but it should also verify unmount cleanup (disconnect and pending frame cancellation) to lock in the full behavior of this change.

Based on learnings, Write behaviour-driven tests, not implementation-driven ones. Tests should validate real expected output and observable behaviour, not internal details or mocked-out logic unless absolutely necessary.
As per coding guidelines, Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/components/CodeEditor/index.spec.js` around lines 14 -
51, Add a new test that verifies unmount/cleanup behavior for the new resize
flow: instantiate CodeEditor, mock window.ResizeObserver to return an object
with observe and disconnect (spy on disconnect), mock
window.requestAnimationFrame to call the callback and return an id (e.g., 1) and
mock window.cancelAnimationFrame (spy), call codeEditor.setupResizeObserver()
and capture any returned cleanup function (or use
codeEditor._resizeObserver.disconnect if no return), then invoke the cleanup and
assert that disconnect was called and window.cancelAnimationFrame was called
with the frame id, and finally trigger resizeCallback again and assert
codeEditor.editor.refresh is not called a second time; reference CodeEditor,
setupResizeObserver, editor.refresh, _resizeObserver.disconnect, and
window.cancelAnimationFrame in the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bruno-app/src/components/CodeEditor/index.spec.js`:
- Around line 14-51: Add a new test that verifies unmount/cleanup behavior for
the new resize flow: instantiate CodeEditor, mock window.ResizeObserver to
return an object with observe and disconnect (spy on disconnect), mock
window.requestAnimationFrame to call the callback and return an id (e.g., 1) and
mock window.cancelAnimationFrame (spy), call codeEditor.setupResizeObserver()
and capture any returned cleanup function (or use
codeEditor._resizeObserver.disconnect if no return), then invoke the cleanup and
assert that disconnect was called and window.cancelAnimationFrame was called
with the frame id, and finally trigger resizeCallback again and assert
codeEditor.editor.refresh is not called a second time; reference CodeEditor,
setupResizeObserver, editor.refresh, _resizeObserver.disconnect, and
window.cancelAnimationFrame in the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6e5795d-1cec-4c48-aff4-0aeadc76c18d

📥 Commits

Reviewing files that changed from the base of the PR and between 13a9f9b and e88191e.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/CodeEditor/index.js
  • packages/bruno-app/src/components/CodeEditor/index.spec.js

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/request/editor-layout/code-editor-layout-resize.spec.ts`:
- Around line 33-47: The helper getEditorLayoutState reads CodeMirror internals
(cm.display.lastWrapHeight); instead replace that with observable DOM
measurements: stop accessing cm, instead return the CodeMirror root element's
boundingClientRect height and a stable DOM-derived metric (e.g., the editor
content container's scrollHeight or the .CodeMirror-scroll inner element height)
by querying the 'request-body-editor' test id and the '.CodeMirror' node; update
tests to compare those DOM heights before/after resize rather than relying on
cm.display.lastWrapHeight so assertions rely on public, observable layout
changes.
🪄 Autofix (Beta)

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

Run ID: 2b8f63d5-d6fb-4b44-a8ec-75f2843f65c0

📥 Commits

Reviewing files that changed from the base of the PR and between e88191e and 8907102.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/CodeEditor/index.spec.js
  • tests/request/editor-layout/code-editor-layout-resize.spec.ts
💤 Files with no reviewable changes (1)
  • packages/bruno-app/src/components/CodeEditor/index.spec.js

Comment thread tests/request/editor-layout/code-editor-layout-resize.spec.ts Outdated
@prateek-bruno prateek-bruno force-pushed the bugfix/artifacts-in-file-editor branch from 8907102 to 0f54131 Compare April 29, 2026 13:46
@pull-request-size pull-request-size Bot added size/M and removed size/L labels May 4, 2026
Co-authored-by: Prateek Sunal <prtksunal@gmail.com>
@prateek-bruno prateek-bruno force-pushed the bugfix/artifacts-in-file-editor branch from bd3034b to ea6911d Compare May 4, 2026 18:36
@prateek-bruno prateek-bruno changed the title fix: resize CodeEditor on resize fix: add resize listener refresh to CodeEditor and Query Editor May 4, 2026
@prateek-bruno prateek-bruno changed the title fix: add resize listener refresh to CodeEditor and Query Editor fix: refresh code editor and query editor on resize May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant