Skip to content

feat(api-spec): drag-to-resize split pane with persisted width - #7866

Merged
bijin-bruno merged 4 commits into
usebruno:mainfrom
abhishek-bruno:feat/resizable-spec-viewer
May 5, 2026
Merged

bijin-bruno merged 4 commits into
usebruno:mainfrom
abhishek-bruno:feat/resizable-spec-viewer

Conversation

@abhishek-bruno

@abhishek-bruno abhishek-bruno commented Apr 27, 2026 •

Copy link
Copy Markdown
Member

Description

JIRA

Adds a draggable divider between the spec source (CodeMirror) and the rendered preview (SwaggerUI) in both the API Designer (ApiSpecPanel) and the read-only OpenAPI tab (OpenAPISpecTab). Width persists across opens — per-spec for the designer, per-tab for the OpenAPI tab. Double-click the divider to reset to the 50/50 default.

Screen.Recording.2026-04-27.at.6.02.50.PM.mov

What changed

  • New useDragResize hook (hooks/useDragResize) drives the dragbar interaction, clamping, and ResizeObserver-based re-clamp on container size changes.
  • Width persistence via two new actions: updateApiSpecPanelLeftPaneWidth (per-spec, in the apiSpec slice) and updateApiSpecTabLeftPaneWidth (per-tab, in the tabs slice). They're separate because the storage lifetimes differ —
    per-spec width survives close/reopen of the designer; per-tab width is bound to the tab.
  • SpecViewer is now controlled by leftPaneWidth + onLeftPaneWidthChange props; the parent component owns where the width is stored.

Bonus fixes pulled into this PR

  1. OpenAPISpecTab no longer re-fetches on unrelated re-renders. Previously loadSpec's useCallback deps included collection.environments, collection.runtimeVariables, and collection.globalEnvironmentVariables — all of which are rebuilt as fresh references on every RequestTabPanel render via produce(...). The result: setIsLoading(true) would fire on every resize commit (and any other parent re-render), unmounting SpecViewer and causing both panes to flash. Env context now flows through a ref; loadSpec only changes when pathname, uid, or sourceUrl changes.
  2. Loading state for the Swagger preview pane. Spinner overlays the right pane on first mount and after spec changes; unmounts after SwaggerUI fires onComplete (plus a 2-RAF tail so the operation list has time to paint).
  3. Swagger wrapped in React.memo so the preview doesn't re-render on every parent state change during drag.

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.

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

  • New Features

    • Resizable split-pane for the API spec editor with drag handle, double-click reset, and per-tab/spec persisted left-pane width.
    • Preview generation is explicitly controlled and shows a “Generating preview…” overlay until the Swagger preview reports ready.
  • Style

    • Improved dragbar styling, cursor, and selection behavior for smoother resize UX.
  • Tests

    • Added comprehensive tests for drag-resize behavior.
  • Chores

    • .gitignore updated to include generated package dist directories.

Introduce a drag-to-resize split pane for the API Spec viewer and persist left pane width. Adds a new useDragResize hook to manage dragging state and clamping, plus UI: dragbar styles, a loading state for the Swagger preview (onComplete + loader), and memoization of the Swagger renderer. Wire up persisted widths via Redux: add updateApiSpecPanelLeftPaneWidth (apiSpec slice) and updateApiSpecTabLeftPaneWidth (tabs slice), and propagate leftPaneWidth / onLeftPaneWidthChange through ApiSpecPanel, OpenAPISpecTab, RequestTabPanel and SpecViewer. Misc: pass tab uid into OpenAPISpecTab and add .gstack/ to .gitignore.
@coderabbitai

coderabbitai Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3033115c-16ef-49fd-841c-4baedeba330c

📥 Commits

Reviewing files that changed from the base of the PR and between 1f3da6e and 191dafc.

📒 Files selected for processing (1)
  • .gitignore
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

Walkthrough

Adds a draggable, resizable left/right split for the API Spec viewer via a new useDragResize hook, persists left-pane width in Redux (per-spec and per-tab), updates SpecViewer and related components to use the new props and flow (including readiness gating for Swagger preview), and forwards an onComplete callback to the Swagger renderer. Also updates .gitignore to include packages/bruno-converters/dist.

Changes

Api Spec Panel: Resizable Split

Layer / File(s) Summary
Data Shape / Actions
packages/bruno-app/src/providers/ReduxStore/slices/apiSpec.js, packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
Adds updateApiSpecPanelLeftPaneWidth and updateApiSpecTabLeftPaneWidth actions and exports them for persisting left-pane width on specs and tabs.
Hook (Core)
packages/bruno-app/src/hooks/useDragResize/index.js
New useDragResize({ containerRef, width, onWidthChange, minLeft, minRight }) hook implementing drag state, clamping, document mouse handlers, double-click reset, and a ResizeObserver-based re-clamp that calls onWidthChange when needed; returns { dragging, dragWidth, dragbarProps }.
Hook (Tests)
packages/bruno-app/src/hooks/useDragResize/index.spec.js
Comprehensive Jest tests covering drag lifecycle, clamping, commit on mouseup, double-click reset, no-op mousemove when not dragging, and ResizeObserver re-clamp behavior.
UI: Viewer & Styling
packages/bruno-app/src/components/ApiSpecPanel/SpecViewer.js, packages/bruno-app/src/components/ApiSpecPanel/StyledWrapper.js
SpecViewer accepts leftPaneWidth and onLeftPaneWidthChange, uses useDragResize with a container ref, introduces swaggerReady flow to delay preview until onComplete, and restructures DOM into left pane / dragbar / right pane; CSS updated for dragbar, col-resize cursor and handle hover styling.
Renderer
packages/bruno-app/src/components/ApiSpecPanel/Renderers/Swagger/index.js
Swagger component now accepts an onComplete prop forwarded to SwaggerUI and the default export is wrapped with React.memo.
Integration / Prop Flow
packages/bruno-app/src/components/ApiSpecPanel/index.js, packages/bruno-app/src/components/OpenAPISpecTab/index.js, packages/bruno-app/src/components/RequestTabPanel/index.js
Passes leftPaneWidth and onLeftPaneWidthChange through component tree; OpenAPISpecTab adds tabUid prop and stabilizes env context via ref to reduce reloads; RequestTabPanel forwards current tab uid into OpenAPISpecTab.
Version Control
.gitignore
Adds packages/bruno-converters/dist to the ignored packages dist list.

Sequence Diagram

sequenceDiagram
    participant User
    participant RequestTabPanel as RequestTabPanel
    participant OpenAPISpecTab as OpenAPISpecTab
    participant SpecViewer as SpecViewer
    participant DragHook as useDragResize
    participant Redux as Redux Store
    participant Swagger as SwaggerUI

    RequestTabPanel->>OpenAPISpecTab: render(collection, tabUid)
    OpenAPISpecTab->>SpecViewer: render(content, leftPaneWidth, onLeftPaneWidthChange)
    User->>SpecViewer: mousedown on dragbar
    SpecViewer->>DragHook: onMouseDown()
    DragHook->>DragHook: start dragging (dragWidth)
    User->>DragHook: mousemove
    DragHook->>SpecViewer: update dragWidth (visual feedback)
    User->>DragHook: mouseup
    DragHook->>Redux: onWidthChange(finalWidth)
    Redux->>OpenAPISpecTab: state updated (apiSpecLeftPaneWidth)
    OpenAPISpecTab->>SpecViewer: leftPaneWidth prop updated
    SpecViewer->>Swagger: render with onComplete callback
    Swagger->>SpecViewer: onComplete() -> set swaggerReady
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • usebruno/bruno#6337 — Introduced/modified ApiSpecPanel and Swagger renderer files that this PR extends.

Suggested reviewers

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

Poem

A bar that tugs, a pane that slides,
Redux remembers where it hides,
Drag to fit and double-click to free,
Preview waits until it’s ready to be. 🎛️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the primary feature: adding drag-to-resize functionality to a split pane with persisted width state.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

42-50: Drop the no-deps useEffect and assign the ref inline.

The effect runs on every render anyway and just mirrors the latest collection env fields into a ref. Assigning during render is the canonical "latest value" pattern, removes the effect schedule, and removes a per-render closure allocation.

♻️ Proposed refactor
   const envContextRef = useRef({});
-  useEffect(() => {
-    envContextRef.current = {
-      activeEnvironmentUid: collection?.activeEnvironmentUid,
-      environments: collection?.environments,
-      runtimeVariables: collection?.runtimeVariables,
-      globalEnvironmentVariables: collection?.globalEnvironmentVariables
-    };
-  });
+  envContextRef.current = {
+    activeEnvironmentUid: collection?.activeEnvironmentUid,
+    environments: collection?.environments,
+    runtimeVariables: collection?.runtimeVariables,
+    globalEnvironmentVariables: collection?.globalEnvironmentVariables
+  };

As per coding guidelines: "Avoid useEffect unless absolutely needed. Prefer derived state, event handlers."

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

In `@packages/bruno-app/src/components/OpenAPISpecTab/index.js` around lines 42 -
50, Remove the no-deps useEffect that mirrors collection into the ref and
instead assign envContextRef.current directly during render; replace the
useEffect block that references envContextRef, useRef, and collection with a
direct assignment to envContextRef.current = { activeEnvironmentUid:
collection?.activeEnvironmentUid, environments: collection?.environments,
runtimeVariables: collection?.runtimeVariables, globalEnvironmentVariables:
collection?.globalEnvironmentVariables } so the ref always holds the latest
collection values without scheduling an effect or allocating a per-render
closure.
packages/bruno-app/src/components/ApiSpecPanel/SpecViewer.js (1)

53-61: Reset swaggerReady synchronously to avoid a brief flash of the previous preview.

useEffect fires after the new content has already been committed to the Swagger child, so during the gap between commit and the effect re-render the user can briefly see the old (or transitioning) Swagger DOM before the overlay reappears. Tracking previous content with a ref and updating during render eliminates the gap.

♻️ Proposed refactor
-  const [swaggerReady, setSwaggerReady] = useState(false);
-  useEffect(() => {
-    setSwaggerReady(false);
-  }, [content]);
+  const [swaggerReady, setSwaggerReady] = useState(false);
+  const prevContentRef = useRef(content);
+  if (prevContentRef.current !== content) {
+    prevContentRef.current = content;
+    setSwaggerReady(false);
+  }
   const handleSwaggerComplete = useCallback(() => {
     requestAnimationFrame(() => {
       requestAnimationFrame(() => setSwaggerReady(true));
     });
   }, []);

As per coding guidelines: "Avoid useEffect unless absolutely needed. Prefer derived state, event handlers."

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

In `@packages/bruno-app/src/components/ApiSpecPanel/SpecViewer.js` around lines 53
- 61, Replace the post-paint useEffect that resets swaggerReady with a
synchronous update: track previous content using a ref (prevContentRef) and call
setSwaggerReady(false) inside a useLayoutEffect that watches content so the
reset happens before the browser paints (eliminating the flash); keep
handleSwaggerComplete as-is but ensure prevContentRef is updated to the new
content within that layout-effect so the overlay is shown only after the new
Swagger has signaled completion.
packages/bruno-app/src/hooks/useDragResize/index.js (2)

80-87: Attach mousemove / mouseup only while dragging.

These listeners live on document for the lifetime of the hook even when no drag is in progress, so every mouse motion in the app fires handleMouseMove just to early-return. They also re-register whenever onWidthChange (and hence handleMouseUp) changes identity in the parent. Bind them on onMouseDown and tear them down in handleMouseUp instead.

♻️ Suggested wiring
-  const onMouseDown = useCallback(
-    (e) => {
-      e.preventDefault();
-      const rect = containerRef.current?.getBoundingClientRect();
-      const seed = width != null ? width : rect ? rect.width / 2 : null;
-      dragWidthRef.current = seed;
-      setDragWidth(seed);
-      draggingRef.current = true;
-      setDragging(true);
-    },
-    [containerRef, width]
-  );
+  const onMouseDown = useCallback(
+    (e) => {
+      e.preventDefault();
+      const rect = containerRef.current?.getBoundingClientRect();
+      const seed = width != null ? width : rect ? rect.width / 2 : null;
+      dragWidthRef.current = seed;
+      setDragWidth(seed);
+      draggingRef.current = true;
+      setDragging(true);
+      document.addEventListener('mousemove', handleMouseMove);
+      document.addEventListener('mouseup', handleMouseUp);
+    },
+    [containerRef, width, handleMouseMove, handleMouseUp]
+  );
@@
-  useEffect(() => {
-    document.addEventListener('mousemove', handleMouseMove);
-    document.addEventListener('mouseup', handleMouseUp);
-    return () => {
-      document.removeEventListener('mousemove', handleMouseMove);
-      document.removeEventListener('mouseup', handleMouseUp);
-    };
-  }, [handleMouseMove, handleMouseUp]);
+  // Detach on unmount in case the component disappears mid-drag.
+  useEffect(() => {
+    return () => {
+      document.removeEventListener('mousemove', handleMouseMove);
+      document.removeEventListener('mouseup', handleMouseUp);
+    };
+  }, [handleMouseMove, handleMouseUp]);

And inside handleMouseUp, remove the listeners after a successful drag:

       draggingRef.current = false;
+      document.removeEventListener('mousemove', handleMouseMove);
+      document.removeEventListener('mouseup', handleMouseUp);
       const finalWidth = dragWidthRef.current;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/hooks/useDragResize/index.js` around lines 80 - 87,
Remove the always-active document listeners in the useEffect and instead
register 'mousemove' and 'mouseup' on document when a drag starts (in the
function that handles mousedown / start dragging) and unregister them inside
handleMouseUp (and also on component unmount). Specifically: stop adding
listeners in the existing useEffect block, add
document.addEventListener('mousemove', handleMouseMove) and
document.addEventListener('mouseup', handleMouseUp) inside the
mousedown/start-drag handler (e.g., handleMouseDown/startDrag), and remove them
at the end of handleMouseUp; also ensure a cleanup in a useEffect that removes
listeners on unmount (guarded by refs) so changing onWidthChange/handleMouseUp
identity doesn't leak listeners.

91-102: Defer the re-clamp dispatch to avoid a ResizeObserver loop warning.

onWidthChange(clamped) is invoked synchronously inside the ResizeObserver callback. If the resulting state update changes the container's layout in the same frame, browsers emit ResizeObserver loop completed with undelivered notifications. Wrapping the dispatch in requestAnimationFrame (and cancelling on cleanup) sidesteps it cheaply.

♻️ Sketch
   useEffect(() => {
     if (width == null || !containerRef.current) return;
     const el = containerRef.current;
+    let rafId = 0;
     const ro = new ResizeObserver(() => {
-      const clamped = clamp(width);
-      if (clamped !== width && onWidthChange) {
-        onWidthChange(clamped);
-      }
+      cancelAnimationFrame(rafId);
+      rafId = requestAnimationFrame(() => {
+        const clamped = clamp(width);
+        if (clamped !== width && onWidthChange) {
+          onWidthChange(clamped);
+        }
+      });
     });
     ro.observe(el);
-    return () => ro.disconnect();
+    return () => {
+      cancelAnimationFrame(rafId);
+      ro.disconnect();
+    };
   }, [width, clamp, onWidthChange, containerRef]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/hooks/useDragResize/index.js` around lines 91 - 102,
The ResizeObserver callback inside the useEffect in useDragResize currently
calls onWidthChange(clamped) synchronously and can trigger a "ResizeObserver
loop" warning; instead, schedule the dispatch inside requestAnimationFrame
(store the frame id in a variable) when clamped !== width and onWidthChange
exists, and on cleanup cancel the pending frame with cancelAnimationFrame in
addition to ro.disconnect(); keep the existing clamp, containerRef, ro.observe
and ro.disconnect logic but replace the direct onWidthChange call with an
rAF-scheduled call and clear that rAF on effect cleanup.
🤖 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/ApiSpecPanel/SpecViewer.js`:
- Around line 53-61: Replace the post-paint useEffect that resets swaggerReady
with a synchronous update: track previous content using a ref (prevContentRef)
and call setSwaggerReady(false) inside a useLayoutEffect that watches content so
the reset happens before the browser paints (eliminating the flash); keep
handleSwaggerComplete as-is but ensure prevContentRef is updated to the new
content within that layout-effect so the overlay is shown only after the new
Swagger has signaled completion.

In `@packages/bruno-app/src/components/OpenAPISpecTab/index.js`:
- Around line 42-50: Remove the no-deps useEffect that mirrors collection into
the ref and instead assign envContextRef.current directly during render; replace
the useEffect block that references envContextRef, useRef, and collection with a
direct assignment to envContextRef.current = { activeEnvironmentUid:
collection?.activeEnvironmentUid, environments: collection?.environments,
runtimeVariables: collection?.runtimeVariables, globalEnvironmentVariables:
collection?.globalEnvironmentVariables } so the ref always holds the latest
collection values without scheduling an effect or allocating a per-render
closure.

In `@packages/bruno-app/src/hooks/useDragResize/index.js`:
- Around line 80-87: Remove the always-active document listeners in the
useEffect and instead register 'mousemove' and 'mouseup' on document when a drag
starts (in the function that handles mousedown / start dragging) and unregister
them inside handleMouseUp (and also on component unmount). Specifically: stop
adding listeners in the existing useEffect block, add
document.addEventListener('mousemove', handleMouseMove) and
document.addEventListener('mouseup', handleMouseUp) inside the
mousedown/start-drag handler (e.g., handleMouseDown/startDrag), and remove them
at the end of handleMouseUp; also ensure a cleanup in a useEffect that removes
listeners on unmount (guarded by refs) so changing onWidthChange/handleMouseUp
identity doesn't leak listeners.
- Around line 91-102: The ResizeObserver callback inside the useEffect in
useDragResize currently calls onWidthChange(clamped) synchronously and can
trigger a "ResizeObserver loop" warning; instead, schedule the dispatch inside
requestAnimationFrame (store the frame id in a variable) when clamped !== width
and onWidthChange exists, and on cleanup cancel the pending frame with
cancelAnimationFrame in addition to ro.disconnect(); keep the existing clamp,
containerRef, ro.observe and ro.disconnect logic but replace the direct
onWidthChange call with an rAF-scheduled call and clear that rAF on effect
cleanup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0e160176-fb7c-43c7-9790-77a8205a2a48

📥 Commits

Reviewing files that changed from the base of the PR and between 9361393 and e018384.

📒 Files selected for processing (10)
  • .gitignore
  • packages/bruno-app/src/components/ApiSpecPanel/Renderers/Swagger/index.js
  • packages/bruno-app/src/components/ApiSpecPanel/SpecViewer.js
  • packages/bruno-app/src/components/ApiSpecPanel/StyledWrapper.js
  • packages/bruno-app/src/components/ApiSpecPanel/index.js
  • packages/bruno-app/src/components/OpenAPISpecTab/index.js
  • packages/bruno-app/src/components/RequestTabPanel/index.js
  • packages/bruno-app/src/hooks/useDragResize/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/apiSpec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js

… management

- Updated SpecViewer to enhance loading state handling for Swagger content, ensuring a smoother user experience by preventing flashes of unrendered content.
- Refactored OpenAPISpecTab to streamline environment context management, optimizing the loading process for OpenAPI specifications.
- Simplified the useDragResize hook by removing unnecessary references and improving the handling of drag events, ensuring better performance and responsiveness during resizing actions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

116-129: ⚡ Quick win

Add a no-move drag commit regression test for out-of-range persisted widths.

Please add a case where width starts out of bounds, then onMouseDown → immediate mouseup (no mousemove), and assert the committed value is clamped. This path isn’t covered today and would catch seed/commit edge regressions quickly.

As per coding guidelines: "Cover both the 'happy path' and the realistically problematic paths."

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

In `@packages/bruno-app/src/hooks/useDragResize/index.spec.js` around lines 116 -
129, Add a new unit test to cover the no-move commit when the initial width is
out of allowed bounds: use renderDragResize with a starting width outside the
allowed range, call result.current.dragbarProps.onMouseDown(...) and then
immediately fireMouse('mouseup', <position>) without any mousemove, and assert
onWidthChange was called once with the clamped value (not the raw out-of-range
input) and that result.current.dragging is false and result.current.dragWidth is
null; reference the existing test helpers renderDragResize, fireMouse and the
dragbarProps.onMouseDown handler to implement this regression test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-app/src/hooks/useDragResize/index.js`:
- Around line 61-63: The seeded width assigned in useDragResize (seed computed
from width or rect) must be clamped to the current allowed range before
persisting; update the seed calculation in the onMouseDown/start logic to
compute seed = width != null ? width : rect ? rect.width / 2 : null, then
immediately clamp it to the pane bounds (use your existing min/max or compute
from container/resizer logic) before setting dragWidthRef.current and calling
setDragWidth(seedClamped) so an immediate mouseup cannot commit an out-of-bounds
width.

---

Nitpick comments:
In `@packages/bruno-app/src/hooks/useDragResize/index.spec.js`:
- Around line 116-129: Add a new unit test to cover the no-move commit when the
initial width is out of allowed bounds: use renderDragResize with a starting
width outside the allowed range, call
result.current.dragbarProps.onMouseDown(...) and then immediately
fireMouse('mouseup', <position>) without any mousemove, and assert onWidthChange
was called once with the clamped value (not the raw out-of-range input) and that
result.current.dragging is false and result.current.dragWidth is null; reference
the existing test helpers renderDragResize, fireMouse and the
dragbarProps.onMouseDown handler to implement this regression test.
🪄 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: 7dd13019-fd4e-43fc-9eae-6c8cbbf9923a

📥 Commits

Reviewing files that changed from the base of the PR and between e018384 and ed43095.

📒 Files selected for processing (4)
  • packages/bruno-app/src/components/ApiSpecPanel/SpecViewer.js
  • packages/bruno-app/src/components/OpenAPISpecTab/index.js
  • packages/bruno-app/src/hooks/useDragResize/index.js
  • packages/bruno-app/src/hooks/useDragResize/index.spec.js
✅ Files skipped from review due to trivial changes (1)
  • packages/bruno-app/src/components/ApiSpecPanel/SpecViewer.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/components/OpenAPISpecTab/index.js

- Updated the useDragResize hook to clamp the width seed value, ensuring it stays within defined bounds during drag events.
- Added a new test case to verify that an out-of-bounds width seed is correctly clamped and persisted on immediate mouseup, enhancing the robustness of the drag-resize functionality.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/hooks/useDragResize/index.js (1)

92-105: ⚡ Quick win

onWidthChange in deps can still cause observer rebuilds if callers don't memoize.

The widthRef pattern was introduced specifically to avoid observer teardown on every width change (line 90–91), but onWidthChange is still a plain dep. A future caller that doesn't wrap its callback in useCallback will rebuild the observer on every render. Applying the same ref trick here closes that gap consistently.

♻️ Proposed refactor
 const widthRef = useRef(width);
 widthRef.current = width;
+const onWidthChangeRef = useRef(onWidthChange);
+onWidthChangeRef.current = onWidthChange;
 const hasWidth = width != null;
 useEffect(() => {
   if (!hasWidth || !containerRef.current) return;
   const ro = new ResizeObserver(() => {
     const clamped = clamp(widthRef.current);
-    if (clamped !== widthRef.current && onWidthChange) {
-      onWidthChange(clamped);
+    if (clamped !== widthRef.current && onWidthChangeRef.current) {
+      onWidthChangeRef.current(clamped);
     }
   });
   ro.observe(containerRef.current);
   return () => ro.disconnect();
- }, [hasWidth, clamp, onWidthChange, containerRef]);
+ }, [hasWidth, clamp, containerRef]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/hooks/useDragResize/index.js` around lines 92 - 105,
The ResizeObserver is still rebuilt when callers don't memoize onWidthChange;
create an onWidthChangeRef (useRef) and assign onWidthChangeRef.current =
onWidthChange inside the hook, then use onWidthChangeRef.current inside the
ResizeObserver callback instead of the onWidthChange variable; update the effect
dependencies to remove onWidthChange and include only hasWidth, clamp,
containerRef (or an onWidthChangeRef if you prefer) so the observer won't tear
down on every render while preserving correct calls to onWidthChange.
🤖 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/hooks/useDragResize/index.js`:
- Around line 92-105: The ResizeObserver is still rebuilt when callers don't
memoize onWidthChange; create an onWidthChangeRef (useRef) and assign
onWidthChangeRef.current = onWidthChange inside the hook, then use
onWidthChangeRef.current inside the ResizeObserver callback instead of the
onWidthChange variable; update the effect dependencies to remove onWidthChange
and include only hasWidth, clamp, containerRef (or an onWidthChangeRef if you
prefer) so the observer won't tear down on every render while preserving correct
calls to onWidthChange.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7610c259-a880-4982-b3f3-61702f9cbc74

📥 Commits

Reviewing files that changed from the base of the PR and between ed43095 and 1f3da6e.

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

Delete the .gstack/ ignore entry and normalize the packages/bruno-converters/dist entry in .gitignore (deduplicated). No code changes; just tidy up ignore rules.
@bijin-bruno
bijin-bruno merged commit 04732fa into usebruno:main May 5, 2026
10 checks passed
sharan-bruno pushed a commit to sharan-bruno/bruno that referenced this pull request Jun 4, 2026
…uno#7866)

* Add drag-resize split pane for API Spec viewer

Introduce a drag-to-resize split pane for the API Spec viewer and persist left pane width. Adds a new useDragResize hook to manage dragging state and clamping, plus UI: dragbar styles, a loading state for the Swagger preview (onComplete + loader), and memoization of the Swagger renderer. Wire up persisted widths via Redux: add updateApiSpecPanelLeftPaneWidth (apiSpec slice) and updateApiSpecTabLeftPaneWidth (tabs slice), and propagate leftPaneWidth / onLeftPaneWidthChange through ApiSpecPanel, OpenAPISpecTab, RequestTabPanel and SpecViewer. Misc: pass tab uid into OpenAPISpecTab and add .gstack/ to .gitignore.

* Refactor SpecViewer and OpenAPISpecTab for improved loading and state management

- Updated SpecViewer to enhance loading state handling for Swagger content, ensuring a smoother user experience by preventing flashes of unrendered content.
- Refactored OpenAPISpecTab to streamline environment context management, optimizing the loading process for OpenAPI specifications.
- Simplified the useDragResize hook by removing unnecessary references and improving the handling of drag events, ensuring better performance and responsiveness during resizing actions.

* Enhance useDragResize hook to clamp width seed and improve test coverage

- Updated the useDragResize hook to clamp the width seed value, ensuring it stays within defined bounds during drag events.
- Added a new test case to verify that an out-of-bounds width seed is correctly clamped and persisted on immediate mouseup, enhancing the robustness of the drag-resize functionality.

* Remove .gstack/ from .gitignore

Delete the .gstack/ ignore entry and normalize the packages/bruno-converters/dist entry in .gitignore (deduplicated). No code changes; just tidy up ignore rules.
@coderabbitai coderabbitai Bot mentioned this pull request Jun 24, 2026
5 of 6 tasks
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.

3 participants