Skip to content

feat(mothership): restore attachment previews on draft and add video support#4435

Merged
waleedlatif1 merged 2 commits intostagingfrom
waleedlatif1/mothership-image-preview
May 4, 2026
Merged

feat(mothership): restore attachment previews on draft and add video support#4435
waleedlatif1 merged 2 commits intostagingfrom
waleedlatif1/mothership-image-preview

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Fix missing image preview when navigating away and back to a Mothership draft
  • Derive previewUrl from attachment key on restore via shared getMothershipAttachmentPreviewUrl helper
  • Add video preview support (input chip + sent message) using <video preload="metadata">
  • Dedupe the URL pattern across display-message, use-chat, draft restore, and loadQueuedMessage

Type of Change

  • Bug fix
  • New feature

Testing

Tested manually — attached PNG, switched tasks, returned: preview restored. Attached MP4: first frame shown in input and after send.

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 4, 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 4, 2026 7:37pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 4, 2026

PR Summary

Medium Risk
Moderate UI/runtime risk: changes how preview URLs are derived across draft restore, optimistic messages, and display mapping, and introduces inline <video> rendering which could affect performance or MIME handling.

Overview
Fixes Mothership attachment preview restoration by deriving previewUrl from the persisted attachment key via a shared getMothershipAttachmentPreviewUrl helper (used in display-message, use-chat optimistic messages, draft restore, and queued-message restore).

Adds video preview support: video files now get preview URLs and render as a <video preload="metadata"> thumbnail (both in the input attachment grid and in sent message attachments), while non-previewable files continue to fall back to the document pill/icon UI.

Reviewed by Cursor Bugbot for commit edcf1d2. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR fixes missing attachment previews on Mothership draft restore and adds video preview support (input chip + sent message) by extracting a shared getMothershipAttachmentPreviewUrl helper and wiring it into draft-restore, queued-message-restore, optimistic user messages, and display-message — eliminating four copies of the old image-only inline pattern. Video rendering uses <video preload="metadata"> with a document-icon fallback layer behind it for environments where the first frame doesn't paint automatically.

Confidence Score: 5/5

Safe to merge — the fix is well-scoped and the only finding is a P2 accessibility nit on the video element in chat-message-attachments.

All findings are P2 (missing aria-label on the <video> in chat-message-attachments). The core bug fix and deduplication are correct, and the new video rendering path mirrors the accepted approach already applied to attached-files-list.

apps/sim/app/workspace/[workspaceId]/home/components/chat-message-attachments.tsx — video element missing accessible name.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/chat/attachment-preview.ts New helper that centralises preview URL generation for both image and video attachments, eliminating previous inline duplications.
apps/sim/app/workspace/[workspaceId]/home/components/chat-message-attachments.tsx Adds video thumbnail rendering with icon fallback behind the <video> element; early-exit for missing previewUrl simplifies branching. Missing aria-label on the video element.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/attached-files-list.tsx Extends the input chip to show video previews with an icon fallback, consistent with the chat-message-attachments pattern.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Calls getMothershipAttachmentPreviewUrl in both the draft-restore and queued-message-restore paths to fix missing preview on return to draft.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Replaces inline image-only preview URL logic with the shared helper, adding video support to optimistic messages.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts Extends URL.createObjectURL preview to video files alongside images; blob cleanup on remove/clear/unmount already covers video URLs correctly.
apps/sim/lib/copilot/chat/display-message.ts Deduplicates preview URL generation in toDisplayAttachment using the new shared helper.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[File attached / Draft restored] --> B{Has key?}
    B -- Yes --> C[getMothershipAttachmentPreviewUrl]
    B -- No uploading --> D[URL.createObjectURL blob URL]
    C --> E{media_type?}
    D --> E
    E -- image/ --> F[previewUrl set]
    E -- video/ --> F
    E -- other --> G[previewUrl = undefined]
    F --> H{Render location}
    G --> I[FileAttachmentPill / icon chip]
    H -- attached-files-list input chip --> J{isVideo?}
    H -- chat-message-attachments sent msg --> K{isVideo?}
    J -- Yes --> L[icon fallback + video element]
    J -- No --> M[img element]
    K -- Yes --> N[icon fallback + video element]
    K -- No --> O[img element]
Loading

Reviews (2): Last reviewed commit: "fix(mothership): icon fallback behind vi..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/home/components/chat-message-attachments.tsx Outdated
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

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 edcf1d2. Configure here.

@waleedlatif1 waleedlatif1 merged commit 2f90e41 into staging May 4, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/mothership-image-preview branch May 4, 2026 19:46
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