@devries-cameron20 / t3code-1 / commits / 3b95e7831b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): paused sidebar videos stop reloading after every command (#23106)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Nikita Maximilian Grimm <github@nikitagrimm.de> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Oct 22, 2026 at 10:20 UTC 3b95e7831b11b17627dff16843bc087bfca397ec
8 files changed +161 -13
apps/server/src/assets/AssetAccess.test.ts
+38
@@ -19,6 +19,7 @@ import * as Redacted from "effect/Redacted";
19 import * as Path from "effect/Path";
20 import * as PlatformError from "effect/PlatformError";
21 import * as Schema from "effect/Schema";
22 +import * as TestClock from "effect/testing/TestClock";
23 import { HttpClient, HttpClientResponse, HttpServerResponse } from "effect/http";
24 import { vi } from "vite-plus/test";
25
@@ -602,6 +603,43 @@ describe("AssetAccess", () => {
603 }).pipe(Effect.provide(layerTest)),
604 );
605
606 + it.effect("versions media by file changes rather than by re-signing", () =>
607 + Effect.gen(function* () {
608 + const fs = yield* FileSystem.FileSystem;
609 + const path = yield* Path.Path;
610 + const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-revision-" });
611 + const filePath = path.join(root, "recording.mp4");
612 + yield* fs.writeFileString(filePath, "original");
613 + yield* Effect.promise(() => NodeFSP.utimes(filePath, 1_000, 1_000));
614 + const input = {
615 + resource: {
616 + _tag: "media-file" as const,
617 + threadId: ThreadId.make("thread-1"),
618 + path: filePath,
619 + },
620 + };
621 + const original = yield* issueAssetUrl(input);
622 + expect(original.fileRevision).toEqual(expect.any(String));
623 +
624 + yield* TestClock.adjust("1 minute");
625 + const renewed = yield* issueAssetUrl(input);
626 + expect(renewed.relativeUrl).not.toBe(original.relativeUrl);
627 + expect(renewed.fileRevision).toBe(original.fileRevision);
628 +
629 + yield* fs.writeFileString(filePath, "modified");
630 + yield* Effect.promise(() => NodeFSP.utimes(filePath, 2_000, 2_000));
631 + const edited = yield* issueAssetUrl(input);
632 + expect(edited.fileRevision).not.toBe(original.fileRevision);
633 +
634 + const replacement = path.join(root, "replacement.mp4");
635 + yield* fs.writeFileString(replacement, "modified");
636 + yield* Effect.promise(() => NodeFSP.utimes(replacement, 2_000, 2_000));
637 + yield* fs.rename(replacement, filePath);
638 + const replaced = yield* issueAssetUrl(input);
639 + expect(replaced.fileRevision).not.toBe(edited.fileRevision);
640 + }).pipe(Effect.provide(layerTest)),
641 + );
642 +
643 it.effect("keeps in-place edits readable but requires a new URL after atomic replacement", () =>
644 Effect.gen(function* () {
645 const fs = yield* FileSystem.FileSystem;
apps/server/src/assets/AssetAccess.ts
+6
@@ -396,6 +396,7 @@ const finalizeAbsoluteMediaFileAsset = Effect.fn("AssetAccess.finalizeAbsoluteMe
396 : Effect.succeed(null),
397 (dimensions) => ({
398 identity: { device: file.info.dev.toString(), inode: file.info.ino.toString() },
399 + fileRevision: `${file.info.dev}:${file.info.ino}:${file.info.size}:${file.info.mtimeNs}:${file.info.ctimeNs}`,
400 dimensions,
401 }),
402 ),
@@ -420,6 +421,7 @@ const finalizeAbsoluteMediaFileAsset = Effect.fn("AssetAccess.finalizeAbsoluteMe
421 expiresAt: input.expiresAt,
422 },
423 fileName: path.basename(canonicalFile),
424 + fileRevision: opened.fileRevision,
425 imageDimensions: opened.dimensions,
426 };
427 },
@@ -522,6 +524,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
524 let fileName: string;
525 let sourcePath: string | undefined;
526 let imageDimensions: ImageDimensions | null = null;
527 + let fileRevision: string | undefined;
528
529 switch (input.resource._tag) {
530 case "media-file": {
@@ -549,6 +552,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
552 claims = finalized.claims;
553 fileName = finalized.fileName;
554 imageDimensions = finalized.imageDimensions;
555 + fileRevision = finalized.fileRevision;
556 break;
557 }
558 case "workspace-file": {
@@ -592,6 +596,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
596 claims = finalized.claims;
597 fileName = finalized.fileName;
598 imageDimensions = finalized.imageDimensions;
599 + fileRevision = finalized.fileRevision;
600 break;
601 }
602 const workspaceRoot = yield* workspacePaths.normalizeWorkspaceRoot(draftWorkspaceRoot).pipe(
@@ -847,6 +852,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
852 expiresAt,
853 ...(sourcePath !== undefined ? { sourcePath } : {}),
854 ...(imageDimensions !== null ? { imageDimensions } : {}),
855 + ...(fileRevision !== undefined ? { fileRevision } : {}),
856 };
857 });
858
apps/web/src/components/files/AudioPreview.tsx
+24 -2
@@ -1,17 +1,39 @@
1 +import { useState } from "react";
2 +
3 export function AudioPreview(props: {
4 readonly src: string;
5 readonly name: string;
6 + /** Re-signed URLs with the same revision keep the loaded audio and its position. */
7 + readonly revision?: string | null;
8 readonly onError?: () => void;
9 }) {
10 + const [loadedSource, setLoadedSource] = useState<{ src: string; revision: string } | null>(null);
11 + const [playing, setPlaying] = useState(false);
12 + const revision = props.revision ?? null;
13 + // Changed files load once playback pauses.
14 + if (loadedSource !== null && loadedSource.revision !== revision && !playing) {
15 + setLoadedSource(revision === null ? null : { src: props.src, revision });
16 + }
17 + const src = loadedSource?.src ?? props.src;
18 return (
19 <div className="flex min-h-0 flex-1 items-center justify-center p-6">
20 <audio
21 controls
22 preload="metadata"
11 - src={props.src}
23 + src={src}
24 aria-label={props.name}
25 className="w-full max-w-xl"
14 - onError={props.onError}
26 + onLoadedMetadata={() => {
27 + if (revision !== null && loadedSource === null) setLoadedSource({ src, revision });
28 + }}
29 + onPlay={() => setPlaying(true)}
30 + onPause={() => setPlaying(false)}
31 + onEnded={() => setPlaying(false)}
32 + onError={() => {
33 + setPlaying(false);
34 + setLoadedSource(null);
35 + if (src === props.src) props.onError?.();
36 + }}
37 />
38 </div>
39 );
apps/web/src/components/files/FilePreviewPanel.tsx
+20 -6
@@ -289,10 +289,15 @@ function WorkspaceVideoPreview(props: {
289 void refreshAssetUrl().catch(() => undefined);
290 },
291 });
292 + // Servers that report the file's revision let an unchanged file stay loaded; older ones
293 + // only offer the workspace mutation, which changes after every command. The revision also
294 + // goes in the URL, since two mints in the same millisecond sign identical URLs.
295 + const fileRevision = assetUrl._tag === "Success" ? assetUrl.fileRevision : undefined;
296 + const revision = fileRevision ?? props.workspaceMutationId;
297 const revisionSuffix =
293 - props.workspaceMutationId === null
298 + revision === null
299 ? ""
295 - : `${assetUrl._tag === "Success" && assetUrl.url.includes("?") ? "&" : "?"}workspace-revision=${encodeURIComponent(props.workspaceMutationId)}`;
300 + : `${assetUrl._tag === "Success" && assetUrl.url.includes("?") ? "&" : "?"}${fileRevision !== undefined ? "file" : "workspace"}-revision=${encodeURIComponent(revision)}`;
301 const latestUrl = assetUrl._tag === "Success" ? `${assetUrl.url}${revisionSuffix}` : null;
302
303 return (
@@ -301,7 +306,7 @@ function WorkspaceVideoPreview(props: {
306 src={latestUrl}
307 sourceFailed={assetUrl._tag === "Failure"}
308 label={props.name}
304 - revision={props.workspaceMutationId}
309 + revision={revision}
310 preload="metadata"
311 className="flex h-full min-h-0 w-full max-w-5xl items-center justify-center"
312 onRetry={refreshAssetUrl}
@@ -343,10 +348,12 @@ function WorkspaceAudioPreview(props: {
348 void refreshAssetUrl().catch(() => undefined);
349 },
350 });
351 + const fileRevision = assetUrl._tag === "Success" ? assetUrl.fileRevision : undefined;
352 + const revision = fileRevision ?? props.workspaceMutationId;
353 const revisionSuffix =
347 - props.workspaceMutationId === null
354 + revision === null
355 ? ""
349 - : `${assetUrl._tag === "Success" && assetUrl.url.includes("?") ? "&" : "?"}workspace-revision=${encodeURIComponent(props.workspaceMutationId)}`;
356 + : `${assetUrl._tag === "Success" && assetUrl.url.includes("?") ? "&" : "?"}${fileRevision !== undefined ? "file" : "workspace"}-revision=${encodeURIComponent(revision)}`;
357 const url = assetUrl._tag === "Success" ? `${assetUrl.url}${revisionSuffix}` : null;
358 if (assetUrl._tag === "Failure" || (url !== null && failedUrl === url)) {
359 return (
@@ -360,7 +367,14 @@ function WorkspaceAudioPreview(props: {
367 );
368 }
369 if (url === null) return <FileSurfaceLoading />;
363 - return <AudioPreview src={url} name={props.name} onError={() => setFailedUrl(url)} />;
370 + return (
371 + <AudioPreview
372 + src={url}
373 + name={props.name}
374 + revision={revision}
375 + onError={() => setFailedUrl(url)}
376 + />
377 + );
378 }
379
380 function clampFileLine(contents: string, requestedLine: number): number {
apps/web/src/components/media/MediaVideoPlayer.browser.test.tsx new
+58
@@ -0,0 +1,58 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { act, render, stubGlobal, type Screen } from "../../../test/render";
4 +import { MediaVideoPlayer } from "./MediaVideoPlayer";
5 +
6 +// The observer never reports the video as visible, so it keeps preload="none" and never
7 +// requests these fake URLs; the test fires the media events itself.
8 +class HiddenIntersectionObserver {
9 + observe() {}
10 + disconnect() {}
11 +}
12 +
13 +function expectVideoSrc(screen: Screen, src: string) {
14 + return expect.element(screen.getByLabelText("clip")).toHaveAttribute("src", src);
15 +}
16 +
17 +async function loadMetadata(screen: Screen) {
18 + await act(() => {
19 + screen.getByLabelText("clip").element().dispatchEvent(new Event("loadedmetadata"));
20 + });
21 +}
22 +
23 +describe("MediaVideoPlayer", () => {
24 + it("keeps a loaded paused video when only its URL is re-signed", async () => {
25 + using _observer = stubGlobal("IntersectionObserver", HiddenIntersectionObserver);
26 + await using screen = await render(
27 + <MediaVideoPlayer src="/asset/first/clip.mp4" label="clip" revision="file-1" />,
28 + );
29 + await loadMetadata(screen);
30 +
31 + await screen.rerender(
32 + <MediaVideoPlayer src="/asset/renewed/clip.mp4" label="clip" revision="file-1" />,
33 + );
34 + await expectVideoSrc(screen, "/asset/first/clip.mp4");
35 +
36 + await screen.rerender(
37 + <MediaVideoPlayer src="/asset/changed/clip.mp4" label="clip" revision="file-2" />,
38 + );
39 + await expectVideoSrc(screen, "/asset/changed/clip.mp4");
40 +
41 + // A second re-sign while the changed file is still loading must not restart that load.
42 + await screen.rerender(
43 + <MediaVideoPlayer src="/asset/changed-renewed/clip.mp4" label="clip" revision="file-2" />,
44 + );
45 + await expectVideoSrc(screen, "/asset/changed/clip.mp4");
46 + });
47 +
48 + it("keeps a loaded paused video while its URL is briefly unavailable", async () => {
49 + using _observer = stubGlobal("IntersectionObserver", HiddenIntersectionObserver);
50 + await using screen = await render(
51 + <MediaVideoPlayer src="/asset/first/clip.mp4" label="clip" revision="file-1" />,
52 + );
53 + await loadMetadata(screen);
54 +
55 + await screen.rerender(<MediaVideoPlayer src={null} label="clip" revision="mutation-2" />);
56 + await expectVideoSrc(screen, "/asset/first/clip.mp4");
57 + });
58 +});
apps/web/src/components/media/MediaVideoPlayer.tsx
+11 -5
@@ -60,13 +60,16 @@ export function MediaVideoPlayer({
60 const failed = src !== null ? failedSrc === src : sourceFailed;
61 const preloaded = preloadedSrc === src || typeof IntersectionObserver === "undefined";
62
63 - // Re-signing must not reset the playhead. Changed files refresh once playback pauses.
63 + // Re-signing must not reload a loaded source. Changed files load once playback pauses.
64 if (
65 playbackSource !== null &&
66 playbackSource.revision !== revision &&
67 + (latestSrc !== null || sourceFailed) &&
68 (video === null || playingVideo !== video)
69 ) {
69 - setPlaybackSource(null);
70 + setPlaybackSource(
71 + revision !== null && latestSrc !== null ? { src: latestSrc, revision } : null,
72 + );
73 }
74
75 useEffect(() => {
@@ -174,7 +177,10 @@ export function MediaVideoPlayer({
177 videoClassName,
178 )}
179 style={style}
177 - onLoadedMetadata={(event) => prepareVideoFirstFrame(event.currentTarget)}
180 + onLoadedMetadata={(event) => {
181 + prepareVideoFirstFrame(event.currentTarget);
182 + if (sourceRevision !== null) setPlaybackSource({ src, revision: sourceRevision });
183 + }}
184 onPlay={(event) => {
185 setPlayingVideo(event.currentTarget);
186 setPlaybackSource({ src, revision: sourceRevision });
@@ -183,8 +189,8 @@ export function MediaVideoPlayer({
189 onEnded={() => setPlayingVideo(null)}
190 onError={() => {
191 setPlayingVideo(null);
186 - if (latestSrc !== null && src !== latestSrc) setPlaybackSource(null);
187 - else setFailedSrc(src);
192 + setPlaybackSource(null);
193 + if (latestSrc === null || src === latestSrc) setFailedSrc(src);
194 }}
195 />
196 ) : (
packages/client-runtime/src/state/assets.ts
+2
@@ -80,6 +80,7 @@ export type AssetUrlState =
80 readonly expiresAt: number;
81 readonly sourcePath?: string;
82 readonly imageDimensions?: AssetImageDimensions;
83 + readonly fileRevision?: string;
84 };
85
86 export const MISSING_FILE_ACCESS_MESSAGE =
@@ -124,6 +125,7 @@ export function assetUrlStateFromResult(
125 ...(result.value.imageDimensions !== undefined
126 ? { imageDimensions: result.value.imageDimensions }
127 : {}),
128 + ...(result.value.fileRevision !== undefined ? { fileRevision: result.value.fileRevision } : {}),
129 };
130 }
131
packages/contracts/src/assets.ts
+2
@@ -75,6 +75,8 @@ export const AssetCreateUrlResult = Schema.Struct({
75 TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
76 ),
77 imageDimensions: Schema.optional(AssetImageDimensions),
78 + /** Changes only when the file's contents or identity change, unlike `relativeUrl`, which is re-signed on every mint. */
79 + fileRevision: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(256))),
80 });
81 export type AssetCreateUrlResult = typeof AssetCreateUrlResult.Type;
82