Repository navigation
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:
WalkthroughUpdates WebSocket message scrolling so remounts restore saved positions, new messages still scroll into view, and a regression test covers tab switching with a long-message fixture. ChangesWebSocket scroll preservation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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.
🧹 Nitpick comments (4)
tests/websockets/message-scroll/message-scroll.spec.ts (3)
17-44: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse the
containerlocator instead of re-querying by test id.Line 37 re-queries
page.getByTestId('ws-messages-container')even thoughcontainer(line 17) already points to the same locator. As per path instructions, "Use locator variables for locators" — reusing it keeps the selector centralized and avoids drift if the test id ever changes in one place but not the other.♻️ Proposed fix
await selectRequestPaneTab(page, 'Headers'); - await expect(page.getByTestId('ws-messages-container')).toBeHidden(); + await expect(container).toBeHidden(); await selectRequestPaneTab(page, 'Message');🤖 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 `@tests/websockets/message-scroll/message-scroll.spec.ts` around lines 17 - 44, The test re-queries the same ws-messages-container instead of reusing the existing container locator, which breaks the “use locator variables for locators” pattern. Update the message-scroll spec to reuse the container variable throughout the flow, including after switching tabs and when asserting visibility/scroll position, so the selector stays centralized in the message-scroll test.Source: Path instructions
29-44: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest only exercises
scrollTop = 0, which trivially holds after a full remount.Since switching tabs remounts
WsBody(per the comment on line 36), the messages container is a brand-new DOM node whosescrollTopnaturally starts at 0 — this passes even without any real scroll-position "preservation" logic, it only proves the old forced scroll-to-bottom is gone. Consider also asserting a non-zero starting scroll position (e.g. scroll to the middle) stays put after switching tabs back, if the intent is genuine position preservation rather than just "no forced scroll-to-bottom".🤖 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 `@tests/websockets/message-scroll/message-scroll.spec.ts` around lines 29 - 44, The current message-scroll test only verifies the trivial `scrollTop = 0` case, which can pass on a fresh `WsBody` remount without proving preservation. Update `message-scroll.spec.ts` around the `container.evaluate` and `selectRequestPaneTab` steps to first scroll the `ws-messages-container` to a non-zero position (for example, the middle of the list), then switch from `Message` to `Headers` and back, and assert the restored `scrollTop` still matches the original value. Use the existing `container`, `selectRequestPaneTab`, and `ws-messages-container`/`ws-message-body-0` selectors to keep the test focused on real scroll-position retention.
12-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winWrap the arrange/act/assert phases in
test.step.Path instructions call for promoting
test.step"as much as possible so the generated reports are easier to read." Currently the whole body is one flat sequence; wrapping the "open request", "verify scrollable", "reset scroll", "switch tabs", and "assert no jump" phases intest.stepblocks would make failures easier to localize in reports.🤖 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 `@tests/websockets/message-scroll/message-scroll.spec.ts` around lines 12 - 45, The message-scroll spec is still a flat sequence, so the report lacks clear phase boundaries. In message-scroll.spec.ts, wrap the major arrange/act/assert sections in test.step blocks inside the does not scroll the expanded message list when switching request pane tabs test: opening the request, verifying the container is scrollable, resetting scroll position, switching tabs, and asserting the scroll position stays at the top. Keep the existing assertions and helpers like openRequest, selectRequestPaneTab, and the ws-messages-container checks, but group them into named steps so failures are easier to localize.Source: Path instructions
packages/bruno-app/src/components/RequestPane/WsBody/index.js (1)
63-78: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winFix correctly gates scroll on new-message growth, not just mount.
Consolidating the scroll-to-bottom into this effect and keying it off
messages.length > prevMessagesLengthRef.current(instead of the oldmessages.length > 0check) is the right fix — sinceprevMessagesLengthRefis seeded with the initialmessages.length, tab-switch/remounts won't spuriously trigger a jump to the bottom.One optional improvement: the DOM write (
container.scrollTop = container.scrollHeight) happens in a plainuseEffect, which runs after paint — this can cause a visible one-frame jump for a longer message list. ConsideruseLayoutEffectso the scroll adjustment happens before the browser paints.♻️ Proposed tweak
-import { useCallback, useEffect, useRef, useState } from 'react'; +import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'; ... - useEffect(() => { + useLayoutEffect(() => { if (messages.length > prevMessagesLengthRef.current) {🤖 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/RequestPane/WsBody/index.js` around lines 63 - 78, The scroll-to-bottom logic in WsBody’s useEffect is correct for only handling true message growth via prevMessagesLengthRef, but the DOM update is still happening after paint and can cause a visible jump. Move the scroll adjustment in the messages.length effect to useLayoutEffect so messagesContainerRef.current.scrollTop is set before paint, while keeping the existing new-message gate and the expansion/selection updates tied to the latest message UID.
🤖 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/RequestPane/WsBody/index.js`:
- Around line 63-78: The scroll-to-bottom logic in WsBody’s useEffect is correct
for only handling true message growth via prevMessagesLengthRef, but the DOM
update is still happening after paint and can cause a visible jump. Move the
scroll adjustment in the messages.length effect to useLayoutEffect so
messagesContainerRef.current.scrollTop is set before paint, while keeping the
existing new-message gate and the expansion/selection updates tied to the latest
message UID.
In `@tests/websockets/message-scroll/message-scroll.spec.ts`:
- Around line 17-44: The test re-queries the same ws-messages-container instead
of reusing the existing container locator, which breaks the “use locator
variables for locators” pattern. Update the message-scroll spec to reuse the
container variable throughout the flow, including after switching tabs and when
asserting visibility/scroll position, so the selector stays centralized in the
message-scroll test.
- Around line 29-44: The current message-scroll test only verifies the trivial
`scrollTop = 0` case, which can pass on a fresh `WsBody` remount without proving
preservation. Update `message-scroll.spec.ts` around the `container.evaluate`
and `selectRequestPaneTab` steps to first scroll the `ws-messages-container` to
a non-zero position (for example, the middle of the list), then switch from
`Message` to `Headers` and back, and assert the restored `scrollTop` still
matches the original value. Use the existing `container`,
`selectRequestPaneTab`, and `ws-messages-container`/`ws-message-body-0`
selectors to keep the test focused on real scroll-position retention.
- Around line 12-45: The message-scroll spec is still a flat sequence, so the
report lacks clear phase boundaries. In message-scroll.spec.ts, wrap the major
arrange/act/assert sections in test.step blocks inside the does not scroll the
expanded message list when switching request pane tabs test: opening the
request, verifying the container is scrollable, resetting scroll position,
switching tabs, and asserting the scroll position stays at the top. Keep the
existing assertions and helpers like openRequest, selectRequestPaneTab, and the
ws-messages-container checks, but group them into named steps so failures are
easier to localize.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 38f686a3-e1ab-47f3-8ed0-a6c964413971
📒 Files selected for processing (6)
packages/bruno-app/src/components/RequestPane/WsBody/index.jstests/websockets/message-scroll/fixtures/collection/bruno.jsontests/websockets/message-scroll/fixtures/collection/collection.brutests/websockets/message-scroll/fixtures/collection/ws-long-msg.brutests/websockets/message-scroll/init-user-data/preferences.jsontests/websockets/message-scroll/message-scroll.spec.ts
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/websockets/message-scroll.spec.ts (2)
37-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse the
containerlocator variable.Line 37 re-queries
page.getByTestId('ws-messages-container')instead of reusing thecontainervariable declared at Line 17.As per path instructions, "Use locator variables for locators."♻️ Suggested fix
- await expect(page.getByTestId('ws-messages-container')).toBeHidden(); + await expect(container).toBeHidden();🤖 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 `@tests/websockets/message-scroll.spec.ts` at line 37, The test re-queries the websocket messages container instead of reusing the existing locator variable. Update the assertion in the message-scroll spec to use the already declared container locator from the test setup, so the same locator is reused consistently throughout the test.Source: Path instructions
12-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winWrap test phases in
test.stepfor readable reports.The test lacks any
test.stepsegmentation despite multiple logical phases (open request, verify scrollable, reset scroll, switch tabs, verify scroll position).As per path instructions, "Promote the use of `test.step` as much as possible so the generated reports are easier to read."♻️ Suggested refactor
test('does not scroll the expanded message list when switching request pane tabs', async ({ pageWithUserData: page }) => { - await openRequest(page, COLLECTION_NAME, LONG_MSG_REQ); - - const container = page.getByTestId('ws-messages-container'); - await expect(container).toBeVisible(); - - // The first (long) message is expanded by default. Ensure its editor is - // rendered so the container has enough content to overflow. - await expect(page.getByTestId('ws-message-body-0')).toBeVisible(); - - // the container must actually be scrollable. - await expect - .poll(() => container.evaluate((el) => el.scrollHeight - el.clientHeight)) - .toBeGreaterThan(0); - - // Start from the top of the list. - await container.evaluate((el) => { - el.scrollTop = 0; - }); - await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0); - - // Switch away from the Message tab and back — this remounts WsBody. - await selectRequestPaneTab(page, 'Headers'); - await expect(page.getByTestId('ws-messages-container')).toBeHidden(); - await selectRequestPaneTab(page, 'Message'); - - await expect(container).toBeVisible(); - await expect(page.getByTestId('ws-message-body-0')).toBeVisible(); - - // The scroll position must not have jumped to the bottom on remount. - await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0); + const container = page.getByTestId('ws-messages-container'); + + await test.step('open request with long message', async () => { + await openRequest(page, COLLECTION_NAME, LONG_MSG_REQ); + await expect(container).toBeVisible(); + await expect(page.getByTestId('ws-message-body-0')).toBeVisible(); + await expect + .poll(() => container.evaluate((el) => el.scrollHeight - el.clientHeight)) + .toBeGreaterThan(0); + }); + + await test.step('reset scroll to top', async () => { + await container.evaluate((el) => { + el.scrollTop = 0; + }); + await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0); + }); + + await test.step('switch away from and back to Message tab', async () => { + await selectRequestPaneTab(page, 'Headers'); + await expect(container).toBeHidden(); + await selectRequestPaneTab(page, 'Message'); + await expect(container).toBeVisible(); + await expect(page.getByTestId('ws-message-body-0')).toBeVisible(); + }); + + await test.step('verify scroll position is preserved', async () => { + await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0); + }); });🤖 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 `@tests/websockets/message-scroll.spec.ts` around lines 12 - 45, The test in message-scroll.spec.ts has several distinct phases but is written as one block, which makes Playwright reports harder to read. Split the flow inside the existing test('does not scroll the expanded message list when switching request pane tabs', ...) into multiple test.step sections for the main actions: opening the request via openRequest, verifying the container is scrollable, resetting scrollTop, switching tabs with selectRequestPaneTab, and checking the final scroll position. Keep the existing assertions and helpers (openRequest, selectRequestPaneTab, ws-messages-container, ws-message-body-0) the same, just wrap each logical phase in clear test.step labels.Source: Path instructions
🤖 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 `@tests/websockets/message-scroll.spec.ts`:
- Line 37: The test re-queries the websocket messages container instead of
reusing the existing locator variable. Update the assertion in the
message-scroll spec to use the already declared container locator from the test
setup, so the same locator is reused consistently throughout the test.
- Around line 12-45: The test in message-scroll.spec.ts has several distinct
phases but is written as one block, which makes Playwright reports harder to
read. Split the flow inside the existing test('does not scroll the expanded
message list when switching request pane tabs', ...) into multiple test.step
sections for the main actions: opening the request via openRequest, verifying
the container is scrollable, resetting scrollTop, switching tabs with
selectRequestPaneTab, and checking the final scroll position. Keep the existing
assertions and helpers (openRequest, selectRequestPaneTab,
ws-messages-container, ws-message-body-0) the same, just wrap each logical phase
in clear test.step labels.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8baca53d-83ad-434f-91ad-cd1d4a4dfde1
📒 Files selected for processing (2)
tests/websockets/fixtures/collection/ws-long-msg.brutests/websockets/message-scroll.spec.ts
✅ Files skipped from review due to trivial changes (1)
- tests/websockets/fixtures/collection/ws-long-msg.bru
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-app/src/components/RequestPane/WsBody/index.js (1)
14-15: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winUnbounded module-level
scrollPositionsmap — never evicted.
scrollPositionslives at module scope and only ever grows (handleScrollsets an entry peritem.uid, line 97). Nothing removes an entry when a WS request is deleted or a collection is closed, so this Map accumulates stale entries for the entire app session. Low individual entry cost, but it's an unbounded leak with no cleanup path.♻️ Suggested cleanup approach
+// Consider clearing stale entries when items are removed, e.g. via a +// dispatched delete-item listener, or cap the map size with an LRU eviction. const scrollPositions = new Map();Consider tying eviction to item deletion (e.g., listen for the delete-request action) or capping the map with a simple LRU strategy.
Also applies to: 94-99
🤖 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/RequestPane/WsBody/index.js` around lines 14 - 15, The module-level scrollPositions Map in WsBody is unbounded and never evicted, so stale entries can accumulate for the whole session. Update the WsBody component’s scroll handling (especially handleScroll and the uid-based set/get flow) to remove entries when a WS request/item is deleted or a collection is closed, or replace it with a capped/LRU cache so old scroll positions are discarded.
🤖 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/RequestPane/WsBody/index.js`:
- Around line 14-15: The module-level scrollPositions Map in WsBody is unbounded
and never evicted, so stale entries can accumulate for the whole session. Update
the WsBody component’s scroll handling (especially handleScroll and the
uid-based set/get flow) to remove entries when a WS request/item is deleted or a
collection is closed, or replace it with a capped/LRU cache so old scroll
positions are discarded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f0f46b68-6439-4bfa-a29c-50c34987c4d9
📒 Files selected for processing (2)
packages/bruno-app/src/components/RequestPane/WsBody/index.jstests/websockets/message-scroll.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/websockets/message-scroll.spec.ts
Description
JIRA
Switching request pane tabs (e.g. Message → Headers → Message) caused the WebSocket message list to jump/scroll pushing the expanded message out of view.
Added a Playwright regression test.
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