π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Keep video sound controls available and skip detached preloads
Anand Baburajan2052d0ceff5c
diff --git a/web/apps/space/src/components/feed-video-preloading.ts b/web/apps/space/src/components/feed-video-preloading.tsindex 68a5917475..5f8719ffa6 100644--- a/web/apps/space/src/components/feed-video-preloading.ts+++ b/web/apps/space/src/components/feed-video-preloading.ts@@ -22,6 +22,14 @@ const schedule = () => {if (!queued.size || inFlight >= 2) return;frame ??= requestAnimationFrame(() => {frame = undefined;+ for (const request of queued) {+ if (!request.element.isConnected) {+ queued.delete(request);+ request.reject(+ new DOMException("Video preload canceled", "AbortError"),+ );+ }+ }const next = [...queued].sort((a, b) => distance(a) - distance(b));for (const request of next) {if (inFlight >= 2) break;diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex ef19c349dc..6e0b6a59b9 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -1077,7 +1077,7 @@ const FeedItem: React.FC<FeedItemProps> = ({);const isPhotoReady = Boolean(displayImageUrl) && decodedPhoto.ready;const showSoundControl =- !isPostUnavailable && isPhotoReady && Boolean(activePhoto.video);+ !isPostUnavailable && shouldPreloadVideo && Boolean(activePhoto.video);const canOpenPhoto =!isPostUnavailable && isPhotoReady && Boolean(onOpenPhoto);const openPhoto = (focusReplyOnOpen = false, index = photoIndex) => {diff --git a/web/apps/space/tests/feed-video-preloading.test.ts b/web/apps/space/tests/feed-video-preloading.test.tsindex 00776de071..a335f9f115 100644--- a/web/apps/space/tests/feed-video-preloading.test.ts+++ b/web/apps/space/tests/feed-video-preloading.test.ts@@ -38,14 +38,20 @@ const flush = () => {};const enqueue = (name: string, top: number, slideOffset = 0) => {- const position = { top, slideOffset };+ const position = { top, slideOffset, isConnected: true };const element = {+ get isConnected() {+ return position.isConnected;+ },getBoundingClientRect: () => ({top: position.top - viewport.scrollY,bottom: position.top + 300 - viewport.scrollY,left: 100 + position.slideOffset,}),- closest: () => ({ getBoundingClientRect: () => ({ left: 100 }) }),+ closest: () =>+ position.isConnected+ ? { getBoundingClientRect: () => ({ left: 100 }) }+ : null,} as unknown as HTMLElement;const download = Promise.withResolvers<string>();const load = vi.fn(() => {@@ -118,6 +124,29 @@ test("canceling a queued preload prevents its network request", async () => {expect(frames.size).toBe(0);});+test("detaching a queued video before cleanup does not block other downloads", async () => {+ const detached = enqueue("detached", 100);+ enqueue("next", 500);+ enqueue("last", 900);+ detached.position.isConnected = false;+ flush();+ expect(started).toEqual(["next", "last"]);+ expect(detached.load).not.toHaveBeenCalled();+ await expect(detached.promise).rejects.toMatchObject({+ name: "AbortError",+ });+});++test("a detached video is canceled even when it is the only queued request", async () => {+ const detached = enqueue("detached", 100);+ detached.position.isConnected = false;+ flush();+ expect(started).toEqual([]);+ await expect(detached.promise).rejects.toMatchObject({+ name: "AbortError",+ });+});+test("an in-flight download retains its slot when its post is unmounted", async () => {const first = enqueue("first", 100);enqueue("second", 500);