Repository navigation
fix:serialize object variable values before copying to clipboard - #8362
Conversation
Walkthrough
ChangesVariable display and clipboard handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
Actionable comments posted: 2
🤖 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/utils/codemirror/brunoVarInfo.js`:
- Around line 156-162: The clipboard normalization in the value-copy path now
handles objects via pretty JSON and nullish values via empty-string coercion,
but the current specs only cover string copying. Add/extend tests around the
brunoVarInfo value-copy behavior to verify the function that builds valueStr
produces pretty-printed JSON for object inputs and an empty string for
null/undefined inputs, in addition to the existing string case, so the new
normalization behavior is protected from regressions.
- Around line 156-162: `JSON.stringify` in `brunoVarInfo` can throw for circular
or unsupported object values before the clipboard write runs. Update the copy
flow around the `valueStr` निर्माण to safely handle object formatting with a
guarded stringify and a fallback string path when serialization fails, so
`navigator.clipboard.writeText(...)` still executes. Add or adjust cases in
`brunoVarInfo.spec.js` to cover plain objects and circular/object-serialization
failures.
🪄 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: 99fff671-2e49-429f-a86b-804e1ec34b3d
📒 Files selected for processing (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
b43f920 to
11d296a
Compare
11d296a to
949adc2
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/variable-tooltip/variable-tooltip.spec.ts (1)
679-681: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace fixed
waitForTimeout(500)with a deterministic wait.Per path instructions,
waitForTimeoutshould be avoided unless the locator truly can't be resolved viaexpect(). Here, waiting for the save-in-progress/unsaved indicator to clear (or a save-confirmation signal) would be more reliable and avoid flakiness/slowness.♻️ Suggested approach
await page.getByRole('button', { name: 'Save', exact: true }).first().click(); - await page.waitForTimeout(500); + await expect(page.getByRole('button', { name: 'Save', exact: true }).first()).toBeDisabled();(Adjust to whatever signal reliably indicates the save completed, e.g., unsaved-changes dot disappearing.)
As per path instructions, "Try to reduce usage of
page.waitForTimeout();in code unless absolutely necessary and the locator cannot be found using existingexpect()playwright calls."🤖 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/variable-tooltip/variable-tooltip.spec.ts` around lines 679 - 681, Replace the fixed `page.waitForTimeout(500)` in `variable-tooltip.spec.ts` with a deterministic Playwright wait tied to the save flow. After the `Save` button click in the relevant test block, wait on a stable signal that indicates completion, such as an `expect()` on the unsaved-changes indicator disappearing or a save-confirmation locator becoming visible/invisible. Use the existing test helpers and locators around the `Save` action to keep the wait reliable and avoid flaky timing-based pauses.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/variable-tooltip/variable-tooltip.spec.ts`:
- Around line 679-681: Replace the fixed `page.waitForTimeout(500)` in
`variable-tooltip.spec.ts` with a deterministic Playwright wait tied to the save
flow. After the `Save` button click in the relevant test block, wait on a stable
signal that indicates completion, such as an `expect()` on the unsaved-changes
indicator disappearing or a save-confirmation locator becoming
visible/invisible. Use the existing test helpers and locators around the `Save`
action to keep the wait reliable and avoid flaky timing-based pauses.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a3d0e33e-884d-4408-8d22-6ab17fc2ff67
📒 Files selected for processing (2)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.jstests/variable-tooltip/variable-tooltip.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
Description
Copying a variable with an object value from the hover popup writes [object Object] to the clipboard instead of the actual value.navigator.clipboard.writeText() expects a string. When the resolved variable value is an object passing it directly causes the browser to coerce it to [object Object]. The fix serializes the value with JSON.stringify before writing to the clipboard.
JIRA
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
Bug Fixes
toDisplayStringhelper (prevents copying[object Object]).nullis explicitly displayed/copied asnull.String(value)instead).Shared Utility Changes (bruno-common)
toDisplayString(value, fallback, indentation)inpackages/bruno-common/src/utils/string.ts, with re-export frompackages/bruno-common/src/utils/index.ts.UI Behavior Changes (bruno-app)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.jsto:toDisplayString(while preserving the explicit'null'display).toDisplayString(...)) and pass that string tonavigator.clipboard.writeText(valueStr).Tests
packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.jswith Jest coverage for:String(value).tests/variable-tooltip/variable-tooltip.spec.tsvalidating that an object-typed folder variable: