Skip to content

fix(file): zero byte codegen file format + zoomable preview wrapper + mermaid errors loopback#4400

Merged
icecrasher321 merged 7 commits intostagingfrom
fix/file-prev-new
May 2, 2026
Merged

fix(file): zero byte codegen file format + zoomable preview wrapper + mermaid errors loopback#4400
icecrasher321 merged 7 commits intostagingfrom
fix/file-prev-new

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Zero byte file on creation showed failed fetch error.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 2, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 2, 2026 7:52am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 2, 2026

PR Summary

Medium Risk
Touches file preview/rendering paths (PDF streaming buffers, image/SVG/Mermaid viewers) and expands server-side compiled-check behavior to new file types, which could impact user-visible preview reliability and agent workflows if regressions slip in.

Overview
Improves file preview robustness and adds shared zoom/pan UI. PDF streaming previews now treat zero-length buffers as loading, and image/SVG previews are refactored to use a new reusable ZoomablePreview component.

Expands Mermaid support end-to-end. The compiled-check endpoint and workspace VFS files/by-id/{id}/compiled-check now accept .mmd/.mermaid files by validating Mermaid syntax via new validateMermaidSource, and the Mermaid renderer is updated to better handle streaming content (debounced rendering, source fallback on invalid diagrams) with optional zoom-to-fit for full-file previews.

Fixes streaming content propagation in embedded file views. Embedded file previews now pass through pending (including empty) previewText to avoid “failed fetch” behavior when newly created/generated content starts as zero bytes.

Reviewed by Cursor Bugbot for commit a90cb18. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 2, 2026

Greptile Summary

This PR fixes a zero-byte file preview crash by passing "" instead of undefined as streamingContent so file viewers enter skeleton/streaming mode rather than triggering a failing network fetch. It also adds mermaid diagram validation to the compiled-check flow, introduces a reusable ZoomablePreview component (extracted from ImagePreview), and improves the mermaid streaming experience with debounced rendering and a source-code fallback view during partial/invalid diagrams.

Confidence Score: 5/5

Safe to merge — all findings are P2; the core zero-byte fix is correct and the mermaid server-side issue was already known.

No P0 or P1 issues were found in the new code. The two P2 observations (blank flash on non-streaming mermaid re-render, and pointer-events loss on the SVG iframe) are minor UX concerns that don't affect correctness or data integrity.

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/preview-panel.tsx — blank flash regression and SvgPreview pointer-events change.

Important Files Changed

Filename Overview
apps/sim/lib/mermaid/validate.ts New server-side mermaid validation helper that imports browser-only mermaid package — will silently return {ok: false} in Node.js (already flagged in previous thread).
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/zoomable-preview.tsx New reusable zoom/pan wrapper component extracted from ImagePreview; adds ResizeObserver-based clamping and a debounced zoom ref — well-structured but children are placed inside pointer-events-none, limiting use with interactive content like iframes.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/preview-panel.tsx Significant mermaid streaming improvements: debounced rendering, source-code fallback, streaming context propagation. Non-streaming re-renders produce a brief blank flash (P2) and SvgPreview iframe loses pointer interaction.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx Adds a zero-byte buffer guard to the PDF streaming path so empty buffers show a skeleton instead of attempting to render.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx Core zero-byte fix: pendingOrStreamingFilePreviewText now passes "" instead of undefined so FileViewer enters streaming/skeleton mode for empty files rather than triggering a failing network fetch.
apps/sim/app/api/workspaces/[id]/files/[fileId]/compiled-check/route.ts Extends compiled-check route to support .mmd/.mermaid files via validateMermaidSource; will return {ok: false} for all diagrams in prod because mermaid is browser-only (already in previous thread).
apps/sim/lib/copilot/vfs/workspace-vfs.ts Parallel server-side mermaid validation path added to VFS readFileContent; same browser-only concern as the route applies here.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/image-preview.tsx Simplified to delegate to ZoomablePreview; zoom/pan logic removed from this file with no behavior regression.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/pdf-viewer.tsx Adds .slice(0) defensive copy for buffer-based PDF sources to prevent detached-buffer crashes on re-renders.

Sequence Diagram

sequenceDiagram
    participant AI as AI Agent
    participant VFS as WorkspaceVFS
    participant Validate as validateMermaidSource
    participant RC as ResourceContent
    participant FV as FileViewer
    participant MP as PreviewPanel

    AI->>VFS: readFileContent(files/by-id/{id}/compiled-check)
    VFS->>Validate: validateMermaidSource(code)
    Note over Validate: imports mermaid (browser-only)
    Validate-->>VFS: {ok, error?}
    VFS-->>AI: JSON result

    RC->>RC: pendingOrStreamingFilePreviewText passes '' for zero-byte
    RC->>FV: streamingContent='' (was undefined before fix)
    FV->>FV: streamingContent !== undefined → streaming mode
    FV->>FV: buffer.byteLength === 0 → show skeleton

    FV->>MP: isStreaming=true + content
    MP->>MP: MermaidStreamingCtx.Provider value=true
    MP->>MP: MermaidDiagram(isStreaming=true)
    MP->>MP: 150ms debounce → mermaid.parse suppressErrors
    alt parse ok
        MP-->>FV: render SVG in ZoomablePreview
    else parse fails
        MP-->>FV: MermaidSourcePreview source code fallback
    end
Loading

Reviews (4): Last reviewed commit: "address comments" | Re-trigger Greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8118035. Configure here.

@icecrasher321 icecrasher321 changed the title fix(file): zero byte codegen file format fix(file): zero byte codegen file format + zoomable preview wrapper + mermaid errors loopback May 2, 2026
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/lib/mermaid/validate.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/lib/mermaid/validate.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a90cb18. Configure here.

@icecrasher321 icecrasher321 merged commit 5f3baa4 into staging May 2, 2026
14 checks passed
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.

1 participant