Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(media): unify file and media previews across clients #9253

Mergedjuliusmarmingemerged 8 commits intomain fromt3code/mobile-media-viewersmerged by juliusmarminge View on GitHub

juliusmarmingecommented

What changed

  • Moved markdown file-link parsing, media-source resolution, signed URL state, and media-action availability into client-runtime so web and mobile use the same rules.
  • Routed expanded web videos through the shared streaming player, including URL refresh and retry.
  • Routed every iOS video through AVKit and every iOS image, PDF, and HTML preview through Quick Look.
  • Moved media actions to a long-press on the thumbnail and removed the redundant in-player controls.

Native long-press menus on markdown file chips are in #9258.

Why

The web and mobile clients had separate path parsers, media resolvers, URL lifecycle code, and viewer paths. The copies had already drifted. Some videos downloaded before playback, expired URLs left expanded viewers stuck, and iOS media sometimes opened in React Native viewers instead of AVKit or Quick Look.

This puts the shared decisions in one package and leaves each client responsible only for presentation. On iOS, native viewers own media playback and document preview.

UI changes

Before: clipped initial video controls After: AVKit controls fill the thumbnail

Pre-fix tap and long-press race reproduced on device: screen recording

Testing

  • 40 focused mobile file, markdown, and media tests
  • Mobile TypeScript typecheck
  • TypeScript lint and formatting checks for changed files
  • Native Swift and Kotlin static checks
  • Physical iPhone 16 Pro pass against a disposable LAN environment, covering workspace and external files, images, videos, HTML, PDFs, attachments, composer drafts, markdown embeds, thumbnail long-press menus, AVKit, and Quick Look

Checklist

  • This PR is focused on one media-preview refactor (net negative after splitting out #9258)
  • I explained what changed and why
  • I included before/after screenshots for UI changes
  • I included a recording for interaction changes

Created with gpt-5.6-sol using the Codex harness in T3 Code.

Note

Unify file and media preview parsing and playback across web and mobile

  • Adds shared markdown file-link and media-source resolvers in client-runtime (parseMarkdownFileLink, resolveMediaSource) and replaces local parsing implementations in web, mobile, and the t3-markdown module with these shared helpers
  • Reworks video previews on both platforms to use the shared MediaVideoPlayer; mobile removes the Expo-based VideoPlayback and MediaVideoPreviewModal, and web replaces raw <video> rendering in ExpandedImageDialog, MessagesTimeline, and ChatMarkdown with the shared player
  • Moves AssetUrlState and assetUrlStateFromResult into client-runtime; web and mobile asset URL hooks now derive loading/failure/success through the shared mapper instead of local inline checks
  • Unifies media action menus via a shared MediaActionId union and MediaActionsMenu/useMediaActions; both platforms now expose save/share/open-file actions through the same identifiers and long-press surfaces
  • Risk: resolveViewedImageAsset and ViewedImageAsset now only return media-file resources, removing the attachment-resource variant — callers expecting attachment resources from viewed workspace images will break; iOS FilePreview always uses NativeFilePreview and no longer renders MediaImagePreview for actionable images; MediaVideoPlayer no longer renders an expand/maximize control or accepts an onExpand callback
Macroscope summarized 452f18a.

Note

Medium Risk Broad cross-platform media and preview behavior changes (iOS native viewers, inline vs modal video, shared URL lifecycle) touch high-traffic chat and file flows, though logic is consolidated and covered by focused tests.

Overview Centralizes markdown file-link parsing, media-source classification, signed asset URL state, and media action IDs in client-runtime, then rewires web and mobile to call those helpers instead of duplicated local heuristics.

Mobile drops bespoke link/path code in favor of parseMarkdownFileLink and resolveMediaSource. Video and attachment UX converges on useMediaActions / MediaActionsMenu (long-press on thumbnails); VideoAttachmentMenu, MediaVideoPreviewModal, and the workspace image prefetch atom are removed. iOS routes all full-screen file previews through Quick Look and full-screen videos through AVKit (with URL re-mint on failure); inline/workspace video stays on Expo Video. Composer and thread attachments share attachmentVideoPreviewSource and attachment-scoped asset resources.

Web plays timeline and markdown videos inline via the shared MediaVideoPlayer (no separate “open video” flow or expand control); expanded dialogs stream through the same player with asset refresh. File attachment clicks no longer auto-open a modal for videos. Context menus align action IDs (save, copy-full-path, etc.) and expose save for videos as well as images.

Docs are updated to describe streaming, long-press save/share, and platform-specific players.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 452f18ac5370c47d012af2b0902fa7f5cf2795d7. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.3 KiB13.5 KiB+152 B (+1.1%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB+6 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.6 KiB+146 B (+2.2%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.6 KiB57.0 KiB+1.4 KiB (+2.6%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.3 KiB13.3 KiB+27 B (+0.2%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB−6 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.4 KiB6.4 KiB+33 B (+0.5%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded56.4 KiB56.4 KiB+44 B (+0.1%)66.4 KiB✅
      ClaudeLive turn messages910+1 (+11.1%)21✅

      Baseline: 7751299 · PR result: 452f18a · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. packages/client-runtime/src/markdownLinks.ts line 345Resolvedby juliusmarminge
      packages/client-runtime/src/markdownLinks.ts line 195Resolvedby juliusmarminge
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/344314a6425914943117c993af1b4ee0f923caaf/apps/mobile/src/features/files/WorkspaceFileVideoPreview.tsx#L31

      On iOS, tapping a workspace video now plays it inline through MediaVideoPlayer instead of opening VideoPreviewModal, so the native AVKit presentation behavior is lost. Removing onExpand removed the only path that instantiated the iOS-specific NativeVideoPreview and called NativeControls.presentVideo; restore the expand callback and modal wiring for workspace videos.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/files/WorkspaceFileVideoPreview.tsx around line 31:
      
      On iOS, tapping a workspace video now plays it inline through `MediaVideoPlayer` instead of opening `VideoPreviewModal`, so the native AVKit presentation behavior is lost. Removing `onExpand` removed the only path that instantiated the iOS-specific `NativeVideoPreview` and called `NativeControls.presentVideo`; restore the expand callback and modal wiring for workspace videos.
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This is a cross-client media-preview redesign that changes playback, asset URL minting, sharing, file-link parsing, and action menus across shared runtime, web, and mobile production paths. The new behavior and infrastructure span many existing surfaces, exceeding the scope of an auto-approvable refactor.

      Not approved because:

      • Monthly spending limit reached (workspace setting). Approvability relies on correctness review in order to determine eligibility
      Review your spending limits in [Billing settings](https://app.macroscope.com/pingdotgg/settings/billing). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. packages/client-runtime/src/markdownLinks.ts line 297Resolvedby juliusmarminge
    7. No change here. MediaVideoPlayer renders expo-video's VideoView with nativeControls and native fullscreen enabled on iOS, so AVKit owns playback and fullscreen. Restoring onExpand would bring back the custom Expand control that was intentionally removed.

    8. apps/mobile/src/components/FilePreview.ios.tsx line 50Resolvedby juliusmarminge

Sign in to join this conversation.