Skip to content

fix(ui): Mermaid Copy PNG/SVG should copy images, not fail or copy markup - #12981

Merged
marius-kilocode merged 3 commits into
Kilo-Org:mainfrom
fxnie:fix/mermaid-copy-png-svg-clipboard
Aug 10, 2026
Merged

fix(ui): Mermaid Copy PNG/SVG should copy images, not fail or copy markup#12981
marius-kilocode merged 3 commits into
Kilo-Org:mainfrom
fxnie:fix/mermaid-copy-png-svg-clipboard

Conversation

@fxnie

@fxnie fxnie commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Two clipboard bugs in the Mermaid export actions:

  1. Copy PNG has no effect in VS Code webviews
    copyPng did fetch(dataUrl).blob(). Webview CSP blocks fetch for data: URLs, the promise rejects, and the UI handler only used .then() (no .catch()), so nothing was written to the clipboard and the button showed no success state.

  2. Copy SVG pastes a wall of SVG source text
    onCopySvg called clipboard.writeText(serialize(svg)), so paste targets received markup instead of an image.

Fix

  • Decode the PNG data URL locally (dataUrlToBlob) and write image/png via ClipboardItem
  • Copy SVG as image/svg+xml when ClipboardItem.supports("image/svg+xml"); otherwise fall back to PNG so paste still gets an image
  • Catch copy failures so rejected promises are not silent / unhandled

Download SVG/PNG is unchanged (already bridged via kilo:save-image).

Test plan

  • Render a Mermaid diagram in the VS Code extension webview
  • Copy PNG → paste into Notes/Word/Slack: bitmap appears; button can show “Copied”
  • Copy SVG → paste into an image-capable app: diagram image (SVG or PNG fallback), not <svg>...</svg> text
  • Copy Mermaid source still copies the Mermaid text
  • Download SVG/PNG unchanged / still works

@fxnie
fxnie force-pushed the fix/mermaid-copy-png-svg-clipboard branch from 8645967 to 5bd81ee Compare August 7, 2026 08:57
Comment thread packages/ui/src/kilocode/markdown-mermaid.ts Outdated
Comment thread packages/ui/src/kilocode/markdown-mermaid.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

All 3 suggestions from the previous review were addressed in the new commits: the "kilo-code": patch changeset was added, dataUrlToBlob was extracted to markdown-mermaid-data-url.ts with a real unit test (bun:test, no mocks, matching this directory's precedent), and Copy SVG now writes a multi-representation ClipboardItem (image/svg+xml + image/png + text/plain) with a PNG-only fallback for hosts that reject multi-type items. The new code introduces no issues: the catch fallback is deliberate recovery that reuses the already-rendered PNG blob, errors still propagate to the .catch() in markdown-mermaid-actions.tsx, and there are no memory leaks (only GC-managed Blob/typed-array allocations; no new listeners or subscriptions).

Files Reviewed (4 files)
  • .changeset/mermaid-copy-clipboard-images.md
  • packages/ui/src/kilocode/markdown-mermaid.ts
  • packages/ui/src/kilocode/markdown-mermaid-data-url.ts
  • packages/ui/src/kilocode/markdown-mermaid-data-url.test.ts
Previous Review Summary (commit 5bd81ee)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 5bd81ee)

Status: 3 Issues Found | Recommendation: Address before merge

All findings are non-blocking suggestions. The fix itself is correct: decoding the data URL locally sidesteps the webview CSP fetch(data:) block, errors are no longer swallowed, and no memory leaks were introduced (no new listeners/subscriptions; the Blob/Uint8Array allocations are GC-managed; the setTimeout indicator pattern is pre-existing).

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 3
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/ui/src/kilocode/markdown-mermaid.ts 337 Copy SVG writes only image/svg+xml on modern hosts — consider multiple representations (PNG/text/plain) in one ClipboardItem so SVG-incapable paste targets don't get a silent no-op
packages/ui/src/kilocode/markdown-mermaid.ts 307 dataUrlToBlob is pure but untested; a small unit test would match this directory's precedent (markdown-bidi.test.ts, #12540)
.changeset/ User-facing bug fix ships without a changeset — prior packages/ui fixes used one with "kilo-code": patch (e.g. .changeset/fuzzy-tildes-smile.md)
Files Reviewed (2 files)
  • packages/ui/src/kilocode/markdown-mermaid.ts - 2 issues
  • packages/ui/src/kilocode/markdown-mermaid-actions.tsx - 0 issues

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 37.7K · Output: 7.3K · Cached: 214.3K

Review guidance: REVIEW.md from base branch main

Copy PNG called fetch() on a data URL, which VS Code webview CSP rejects,
so the copy silently did nothing. Decode the data URL locally instead.

Copy SVG used clipboard.writeText() with SVG markup, so paste targets got
source text instead of an image. Write SVG/PNG/text representations when
supported, and fall back to PNG on hosts that reject multi-type items.
@fxnie
fxnie force-pushed the fix/mermaid-copy-png-svg-clipboard branch from 5bd81ee to ead46f4 Compare August 7, 2026 09:06

@marius-kilocode marius-kilocode left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@marius-kilocode
marius-kilocode merged commit 95ad170 into Kilo-Org:main Aug 10, 2026
41 of 43 checks passed
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…-clipboard

fix(ui): Mermaid Copy PNG/SVG should copy images, not fail or copy markup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants