Repository navigation
feat(app): scroll to and highlight error line on script error - #8183
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds Redux signals, a focus utility, and a hook to scroll CodeMirror editors to an error line and apply a transient CSS flash; components dispatch focus on error-card navigation and E2E tests validate highlight, auto-clear, re-trigger, and scrolling. ChangesError-line focus and highlighting
Sequence DiagramsequenceDiagram
participant User
participant ScriptError as ScriptError Card
participant Redux
participant useFocusErrorLine as useFocusErrorLine Hook
participant focusErrorLine as focusErrorLine Util
participant Editor as CodeMirror Editor
User->>ScriptError: Click error file path
ScriptError->>Redux: dispatch setFocusErrorLine(uid, scriptPhase, line, requestedAt)
activate Redux
Redux->>Redux: Store focusErrorLine on tab
deactivate Redux
useFocusErrorLine->>Redux: select focusErrorLine signal
activate useFocusErrorLine
useFocusErrorLine->>useFocusErrorLine: check tab visible + phase match
useFocusErrorLine->>focusErrorLine: call focusErrorLine(editor, line)
activate focusErrorLine
focusErrorLine->>Editor: scroll to line + add cm-error-line-flash classes
focusErrorLine->>focusErrorLine: schedule removal after 3s
deactivate focusErrorLine
focusErrorLine-->>User: line highlights and animates
focusErrorLine->>Editor: remove cm-error-line-flash classes after timeout
useFocusErrorLine->>Redux: dispatch clearFocusErrorLine(uid)
deactivate useFocusErrorLine
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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)
packages/bruno-app/src/utils/codemirror/focusErrorLine.js (1)
6-12: 💤 Low valueConsider early return for empty editors.
When
lineCountis 0, the clamping logic setsline = 0, but the editor has no lines. While thetry/catchbelow handles this safely, an explicit early return would be clearer:export const focusErrorLine = (editor, line1Based, { durationMs = 3000 } = {}) => { if (!editor || typeof line1Based !== 'number' || Number.isNaN(line1Based)) { return () => {}; } const lineCount = editor.lineCount(); + if (lineCount === 0) { + return () => {}; + } const line = Math.max(0, Math.min(line1Based - 1, lineCount - 1));🤖 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/utils/codemirror/focusErrorLine.js` around lines 6 - 12, The function focusErrorLine should explicitly handle empty editors: after calling editor.lineCount() check if lineCount === 0 and return a no-op cleanup immediately instead of continuing; update the logic around the line variable (computed from line1Based and lineCount) only after this check so you don't clamp against an empty editor, and keep the existing try/catch for safety.tests/script-errors/focus-error-line.spec.ts (3)
84-86: 💤 Low valueConsider moving locator definition inside test steps for consistency.
Tests 1, 2, 4, 5, and 6 define their
flashedLinelocator inside the relevant test step, but test 3 defines it outside at lines 84-86. Moving it into the first step would maintain consistency with the other tests.🤖 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/script-errors/focus-error-line.spec.ts` around lines 84 - 86, Move the flashedLine locator definition inside the first test step to match the pattern used by Tests 1, 2, 4, 5, and 6: instead of defining const flashedLine = page.getByTestId('pre-request-script-editor').locator('.CodeMirror .cm-error-line-flash') at the top of the test file, declare that same const within the first step/block of Test 3 so the locator is created in-context and consistently with the other tests.
163-165: ⚡ Quick winPrefer type guard over non-null assertion.
Line 164 checks that
scrollTopis not null, but line 165 uses the non-null assertion operator!. TypeScript best practice is to use a type guard or conditional instead.♻️ Suggested refactor
const scrollTop = await getScrollerScrollTop(page, 'pre-request-script-editor'); expect(scrollTop).not.toBeNull(); - expect(scrollTop!).toBeGreaterThan(0); + expect(scrollTop).toBeGreaterThan(0);Playwright's
expect()will narrow the type after the.not.toBeNull()check, making the assertion operator unnecessary.🤖 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/script-errors/focus-error-line.spec.ts` around lines 163 - 165, The test uses a non-null assertion on scrollTop after already asserting it is not null; change this to a type-safe check by removing the `!` and relying on Playwright's expect() narrowing (or add an explicit type guard like `if (scrollTop === null) throw`), so update the assertions around the getScrollerScrollTop(...) result (`scrollTop`) in focus-error-line.spec.ts to avoid the non-null operator and use a proper type guard or rely on expect's narrowing before calling toBeGreaterThan.
73-74: ⚡ Quick winComment/timeout mismatch.
The comment mentions "Allow 4s" but the timeout is 5000ms (5s). Update the comment to match.
📝 Suggested fix
- // Helper's default duration is 3000ms. Allow 4s for animation end + cleanup. + // Helper's default duration is 3000ms. Allow 5s for animation end + cleanup. await expect(flashedLine).toHaveCount(0, { timeout: 5000 });🤖 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/script-errors/focus-error-line.spec.ts` around lines 73 - 74, The inline comment is incorrect — it says "Allow 4s" while the test uses a 5000ms timeout; update the comment to reflect 5s (or otherwise change the timeout to 4000ms if you prefer) so the comment and code agree; specifically edit the comment above the expect(flashedLine).toHaveCount(0, { timeout: 5000 }) assertion (referencing flashedLine and toHaveCount) to state "Allow 5s for animation end + cleanup."
🤖 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/utils/codemirror/focusErrorLine.js`:
- Around line 6-12: The function focusErrorLine should explicitly handle empty
editors: after calling editor.lineCount() check if lineCount === 0 and return a
no-op cleanup immediately instead of continuing; update the logic around the
line variable (computed from line1Based and lineCount) only after this check so
you don't clamp against an empty editor, and keep the existing try/catch for
safety.
In `@tests/script-errors/focus-error-line.spec.ts`:
- Around line 84-86: Move the flashedLine locator definition inside the first
test step to match the pattern used by Tests 1, 2, 4, 5, and 6: instead of
defining const flashedLine =
page.getByTestId('pre-request-script-editor').locator('.CodeMirror
.cm-error-line-flash') at the top of the test file, declare that same const
within the first step/block of Test 3 so the locator is created in-context and
consistently with the other tests.
- Around line 163-165: The test uses a non-null assertion on scrollTop after
already asserting it is not null; change this to a type-safe check by removing
the `!` and relying on Playwright's expect() narrowing (or add an explicit type
guard like `if (scrollTop === null) throw`), so update the assertions around the
getScrollerScrollTop(...) result (`scrollTop`) in focus-error-line.spec.ts to
avoid the non-null operator and use a proper type guard or rely on expect's
narrowing before calling toBeGreaterThan.
- Around line 73-74: The inline comment is incorrect — it says "Allow 4s" while
the test uses a 5000ms timeout; update the comment to reflect 5s (or otherwise
change the timeout to 4000ms if you prefer) so the comment and code agree;
specifically edit the comment above the expect(flashedLine).toHaveCount(0, {
timeout: 5000 }) assertion (referencing flashedLine and toHaveCount) to state
"Allow 5s for animation end + cleanup."
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 235e9ede-4246-41dc-bf81-6d3dc1c94708
📒 Files selected for processing (13)
packages/bruno-app/src/components/CodeEditor/StyledWrapper.jspackages/bruno-app/src/components/CollectionSettings/Script/index.jspackages/bruno-app/src/components/CollectionSettings/Tests/index.jspackages/bruno-app/src/components/FolderSettings/Script/index.jspackages/bruno-app/src/components/FolderSettings/Tests/index.jspackages/bruno-app/src/components/RequestPane/Script/index.jspackages/bruno-app/src/components/RequestPane/Tests/index.jspackages/bruno-app/src/components/ResponsePane/ScriptError/index.jspackages/bruno-app/src/hooks/useFocusErrorLine/index.jspackages/bruno-app/src/providers/ReduxStore/slices/tabs.jspackages/bruno-app/src/utils/codemirror/focusErrorLine.jstests/script-errors/fixtures/collections/script-errors-test/long-pre-request-error.brutests/script-errors/focus-error-line.spec.ts
Description
JIRA
Contribution Checklist:
Screen.Recording.2026-06-04.at.4.43.11.PM.mov
Summary by CodeRabbit