Skip to content

fix:serialize object variable values before copying to clipboard - #8362

Merged
bijin-bruno merged 4 commits into
usebruno:mainfrom
adwait-bruno:fix/hover-popup-copy-paste-bug
Jul 1, 2026
Merged

bijin-bruno merged 4 commits into
usebruno:mainfrom
adwait-bruno:fix/hover-popup-copy-paste-bug

Conversation

@adwait-bruno

@adwait-bruno adwait-bruno commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • 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

  • Bug Fixes

    • Fixed hover tooltip copy-to-clipboard for non-null object values by serializing resolved values via a shared toDisplayString helper (prevents copying [object Object]).
    • Ensured null is explicitly displayed/copied as null.
    • Added safe fallbacks for non-JSON-serializable/circular values (copies String(value) instead).
  • Shared Utility Changes (bruno-common)

    • Added toDisplayString(value, fallback, indentation) in packages/bruno-common/src/utils/string.ts, with re-export from packages/bruno-common/src/utils/index.ts.
  • UI Behavior Changes (bruno-app)

    • Updated packages/bruno-app/src/utils/codemirror/brunoVarInfo.js to:
      • Render object values using toDisplayString (while preserving the explicit 'null' display).
      • Precompute the clipboard string (toDisplayString(...)) and pass that string to navigator.clipboard.writeText(valueStr).
  • Tests

    • Updated packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js with Jest coverage for:
      • Plain objects copying as pretty-printed JSON.
      • Circular objects copying using String(value).
    • Added a Playwright test in tests/variable-tooltip/variable-tooltip.spec.ts validating that an object-typed folder variable:
      • Shows pretty-printed JSON in the tooltip.
      • Copies the JSON verbatim to the clipboard.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

brunoVarInfo.js now uses shared display-string formatting for variable rendering and clipboard copying. A new common utility is exported for reuse, and tests now cover object and circular values.

Changes

Variable display and clipboard handling

Layer / File(s) Summary
Object rendering and fallback text
packages/bruno-common/src/utils/string.ts, packages/bruno-common/src/utils/index.ts, packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
toDisplayString is added and re-exported, then updateValueDisplay uses it for non-null objects while still showing null explicitly.
Clipboard string normalization and tests
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js, tests/variable-tooltip/variable-tooltip.spec.ts, packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
getCopyButton now writes a normalized string to the clipboard, and tests cover object formatting plus circular-value fallback behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: helloanoop, bijin-bruno, sid-bruno

🚥 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 clearly matches the main change: serializing object variable values before copying them to the clipboard.
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.

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.

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7765320 and b43f920.

📒 Files selected for processing (1)
  • packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

@adwait-bruno
adwait-bruno force-pushed the fix/hover-popup-copy-paste-bug branch from b43f920 to 11d296a Compare June 25, 2026 08:02
@adwait-bruno
adwait-bruno force-pushed the fix/hover-popup-copy-paste-bug branch from 11d296a to 949adc2 Compare July 1, 2026 10:17
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jul 1, 2026

@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)
tests/variable-tooltip/variable-tooltip.spec.ts (1)

679-681: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace fixed waitForTimeout(500) with a deterministic wait.

Per path instructions, waitForTimeout should be avoided unless the locator truly can't be resolved via expect(). 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 existing expect() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 949adc2 and 1d6e986.

📒 Files selected for processing (2)
  • packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
  • tests/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

@bijin-bruno
bijin-bruno merged commit 7b155c0 into usebruno:main Jul 1, 2026
15 of 20 checks passed
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