Skip to content

Preview binary images in the workspace editor - #78

Open
rushabhcodes wants to merge 3 commits into
tscircuit:mainfrom
rushabhcodes:fix/binary-image-previews
Open

rushabhcodes wants to merge 3 commits into
tscircuit:mainfrom
rushabhcodes:fix/binary-image-previews

Conversation

@rushabhcodes

@rushabhcodes rushabhcodes commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opening a binary PNG currently shows “This file cannot be displayed in the editor.” This change opens supported binary images in a fitted preview with a transparency checkerboard and download link.

The preview uses the blob or image data URL already stored in content, falling back to downloadUrl when needed. This avoids a second request for authenticated files. Failed image loads show a fallback message, other binary files keep the download notice, and text SVG files remain editable.

Previews are limited to 5 MiB of encoded data, 16 million pixels, and 8192 pixels per side. Encoded headers are checked before an image element is created; oversized images keep a download-only fallback. Response bodies are read with a byte limit even when Content-Length is absent. Pending checks are canceled on file changes or after 10 seconds, and temporary preview URLs are revoked on cleanup. Only validated bytes are rendered, avoiding a second network request or a changing remote resource.

Adds nine interactive Cosmos examples in examples/binary-files.fixture.tsx: PNG blob URLs, JPEG data URLs, PNG download URLs, failed images, missing image URLs, unsupported binary files, editable SVG source, oversized files, and oversized dimensions. Run bun run dev and open the binary-files fixtures; every example includes a sidebar for switching between images and code, with locally generated sample images.

Before

image

After

image

Validation:

  • bun test: 71 tests pass.
  • bun run typecheck, bun run build, and bun run format:check pass.
  • Chromium checks pass for all nine examples, image sizing, download links, recovery after a failed image, and switching from images back to Monaco. Oversized images never create an image element; unknown-length downloads stop at the byte limit; file changes abort slow checks and revoke previous preview URLs. No uncaught browser errors.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 11:21
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
monaco-code-editor Error Error Oct 12, 2026 12:43pm UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@imrishabh18 imrishabh18 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure if we need this or not. cc @seveibar

Just make sure that we don't load huge images, cause that can freeze the editor

@rushabhcodes

Copy link
Copy Markdown
Contributor Author

will add a limit

@rushabhcodes

Copy link
Copy Markdown
Contributor Author

@imrishabh18 Previews now reject images over 5 MiB

This branch had an error being deployed

1 failed deployment
Preview — 40767618 Deployed Oct 12, 2026 by vercel[bot]
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