Skip to content

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

Open
adwait-bruno wants to merge 2 commits into
usebruno:mainfrom
adwait-bruno:fix/hover-popup-copy-paste-bug
Open

fix:serialize object variable values before copying to clipboard#8362
adwait-bruno wants to merge 2 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.

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
    • Improved copy-to-clipboard behavior by normalizing variable values before copying.
    • Plain objects are now copied as pretty-printed JSON; null is copied as the text null.
    • Circular or non-serializable values now fall back to a safe string representation instead of failing.
  • Tests
    • Added Jest coverage for object and circular-reference copy scenarios.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 1e0db8e2-b57c-4ed6-af13-8aca1b82f1c6

📥 Commits

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

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

Walkthrough

brunoVarInfo.js now renders object values more safely and normalizes clipboard copy text before writing it. The spec adds coverage for copying plain objects and circular objects.

Changes

Variable display and clipboard handling

Layer / File(s) Summary
Object rendering and fallback text
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
updateValueDisplay now shows null as text, stringifies non-null objects with try/catch, and falls back to String(value) if JSON serialization fails.
Clipboard string normalization and tests
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js, packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
getCopyButton now builds a clipboard string from objects or coerced primitives before calling writeText, and the added tests cover pretty-printed object copies and circular-object fallback behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

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

Poem

An object blinked in CodeMirror’s light,
Now rendered and copied just right.
If JSON trips, it takes a fall,
Then String() arrives to save the call,
And clipboard spells come out in sight ✨

🚥 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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment thread packages/bruno-app/src/utils/codemirror/brunoVarInfo.js Outdated
@adwait-bruno adwait-bruno force-pushed the fix/hover-popup-copy-paste-bug branch from b43f920 to 11d296a Compare June 25, 2026 08:02
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.

2 participants