@devries-cameron20 / t3code Mirror · read-only / commits / 23dd7e7007
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 22:00 UTC

revert: "fix(web): preserve snapshot thumbnail context and detail" (#18440) (#22231)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 20, 2026 at 02:03 UTC 23dd7e70073be98a499048268f9af93edab215a4
5 files changed +25 -118
apps/desktop/src/snapShot/SnapShotTransition.ts
+2 -2
@@ -175,7 +175,7 @@ window.prepareCaptureTransition=async destination=>{
175 const inner={width:Math.max(1,target.width-borderWidth*2),height:Math.max(1,target.height-borderWidth*2)};
176 const sourceCenter={x:source.x+source.width/2,y:source.y+source.height/2},targetCenter={x:target.x+target.width/2,y:target.y+target.height/2};
177 const initial="translate3d("+(sourceCenter.x-targetCenter.x)+"px,"+(sourceCenter.y-targetCenter.y)+"px,0) scale("+(source.width/target.width)+","+(source.height/target.height)+")";
178 - const imageWidth=Math.max(1,snapshot.naturalWidth||source.width),imageHeight=Math.max(1,snapshot.naturalHeight||source.height),fit=Math.min(inner.width/imageWidth,inner.height/imageHeight);
178 + const imageWidth=Math.max(1,snapshot.naturalWidth||source.width),imageHeight=Math.max(1,snapshot.naturalHeight||source.height),cover=Math.max(inner.width/imageWidth,inner.height/imageHeight);
179 Object.assign(card.style,{left:target.x+"px",top:target.y+"px",width:target.width+"px",height:target.height+"px",borderRadius:destination.cornerRadius+"px",backgroundColor:destination.backgroundColor,boxShadow:"none"});
180 Object.assign(content.style,{inset:borderWidth+"px",borderRadius:Math.max(0,destination.cornerRadius-borderWidth)+"px"});
181 Object.assign(border.style,{borderWidth:borderWidth+"px",borderColor:destination.borderColor});
@@ -185,7 +185,7 @@ window.prepareCaptureTransition=async destination=>{
185 const animations=[
186 card.animate([{transform:initial},{transform:"translate3d(0,0,0) scale(1)"}],options),
187 content.animate([{transform:"scale("+(target.width/inner.width)+","+(target.height/inner.height)+")"},{transform:"scale(1)"}],options),
188 - snapshot.animate([{transform:"scale(1)"},{transform:"scale("+((imageWidth*fit)/inner.width)+","+((imageHeight*fit)/inner.height)+")"}],options),
188 + snapshot.animate([{transform:"scale(1)"},{transform:"scale("+((imageWidth*cover)/inner.width)+","+((imageHeight*cover)/inner.height)+")"}],options),
189 border.animate([{opacity:0},{opacity:1}],options),
190 details.animate([{opacity:0},{opacity:1}],{delay:Math.max(0,destination.durationMs-125),duration:125,fill:"both",easing:"ease-in"})
191 ];
apps/web/src/components/chat/ChatComposer.tsx
+2 -4
@@ -4923,9 +4923,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4923 {image.previewUrl ? (
4924 <ComposerImageThumbnail
4925 file={image.file}
4926 - mode={image.source?.kind === "snap-shot" ? "snapshot" : "square"}
4926 alt=""
4928 - className="size-full"
4927 + className="size-full object-cover"
4928 fallback={
4929 isHeicImageFile({ name: image.name, type: image.mimeType }) ? (
4930 <AttachmentImage
@@ -6818,9 +6817,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6817 >
6818 <ComposerImageThumbnail
6819 file={image.file}
6821 - mode={image.source?.kind === "snap-shot" ? "snapshot" : "square"}
6820 alt={image.name}
6823 - className="h-full w-full"
6821 + className="h-full w-full object-cover"
6822 fallback={
6823 isHeicImageFile({ name: image.name, type: image.mimeType }) ? (
6824 <AttachmentImage
apps/web/src/components/chat/ComposerImageThumbnail.tsx
+7 -25
@@ -1,47 +1,29 @@
1 import { memo, useEffect, useState, type ReactNode } from "react";
2
3 -import {
4 - createComposerImageThumbnail,
5 - type ComposerImageThumbnailMode,
6 -} from "../../lib/imageCompression";
7 -import { cn } from "../../lib/utils";
3 +import { createComposerImageThumbnail } from "../../lib/imageCompression";
4
5 /** Keep full-resolution image decoding out of composer rerenders. */
6 export const ComposerImageThumbnail = memo(function ComposerImageThumbnail({
7 file,
12 - mode = "square",
8 alt,
9 className,
10 fallback,
11 }: {
12 file: File;
18 - mode?: ComposerImageThumbnailMode;
13 alt: string;
14 className: string;
15 fallback: ReactNode;
16 }) {
23 - const [preview, setPreview] = useState<{
24 - file: File;
25 - mode: ComposerImageThumbnailMode;
26 - src: string | null;
27 - } | null>(null);
17 + const [preview, setPreview] = useState<{ file: File; src: string | null } | null>(null);
18 useEffect(() => {
19 let active = true;
30 - void createComposerImageThumbnail(file, mode).then((src) => {
31 - if (active) setPreview({ file, mode, src });
20 + void createComposerImageThumbnail(file).then((src) => {
21 + if (active) setPreview({ file, src });
22 });
23 return () => {
24 active = false;
25 };
36 - }, [file, mode]);
37 - const src = preview?.file === file && preview.mode === mode ? preview.src : null;
38 - return src ? (
39 - <img
40 - src={src}
41 - alt={alt}
42 - className={cn(className, mode === "snapshot" ? "object-contain" : "object-cover")}
43 - />
44 - ) : (
45 - fallback
46 - );
26 + }, [file]);
27 + const src = preview?.file === file ? preview.src : null;
28 + return src ? <img src={src} alt={alt} className={className} /> : fallback;
29 });
apps/web/src/lib/imageCompression.test.ts
-55
@@ -178,61 +178,6 @@ describe("composer image thumbnails", () => {
178 expect(await original.text()).toBe("original bytes");
179 });
180
181 - it.each([
182 - [3840, 2160, 796, 448],
183 - [3840, 1600, 832, 347],
184 - ])(
185 - "preserves the full %ix%i snapshot within an 832x448 preview without replacing its square thumbnail",
186 - async (sourceWidth, sourceHeight, width, height) => {
187 - const bitmap = { width: sourceWidth, height: sourceHeight, close: vi.fn() };
188 - const decode = vi.fn(async () => bitmap);
189 - const drawImage = vi.fn();
190 - vi.stubGlobal("createImageBitmap", decode);
191 - vi.stubGlobal(
192 - "OffscreenCanvas",
193 - class {
194 - constructor(
195 - public width: number,
196 - public height: number,
197 - ) {}
198 - getContext() {
199 - return { drawImage };
200 - }
201 - async convertToBlob() {
202 - return new Blob([`${this.width}x${this.height}`], { type: "image/png" });
203 - }
204 - },
205 - );
206 - const original = new File(["original bytes"], "window.png", { type: "image/png" });
207 - const square = await createComposerImageThumbnail(original);
208 - const [snapshot, cachedSnapshot] = await Promise.all([
209 - createComposerImageThumbnail(original, "snapshot"),
210 - createComposerImageThumbnail(original, "snapshot"),
211 - ]);
212 -
213 - expect(snapshot).toBe(
214 - `data:image/png;base64,${Buffer.from(`${width}x${height}`).toString("base64")}`,
215 - );
216 - expect(drawImage).toHaveBeenLastCalledWith(
217 - bitmap,
218 - 0,
219 - 0,
220 - sourceWidth,
221 - sourceHeight,
222 - 0,
223 - 0,
224 - width,
225 - height,
226 - );
227 - expect(cachedSnapshot).toBe(snapshot);
228 - expect(await createComposerImageThumbnail(original, "snapshot")).toBe(snapshot);
229 - expect(square).toBe(`data:image/png;base64,${Buffer.from("256x256").toString("base64")}`);
230 - expect(await createComposerImageThumbnail(original)).toBe(square);
231 - expect(decode).toHaveBeenCalledTimes(2);
232 - expect(await original.text()).toBe("original bytes");
233 - },
234 - );
235 -
181 it("releases the decoded image when thumbnail encoding fails", async () => {
182 const close = vi.fn();
183 vi.stubGlobal(
apps/web/src/lib/imageCompression.ts
+14 -32
@@ -204,49 +204,31 @@ async function encodeCanvas(
204 return blob?.type === mimeType ? blob : null;
205 }
206
207 -const COMPOSER_THUMBNAIL_SIZES = {
208 - square: { width: 256, height: 256 },
209 - // The 208x112 snapshot tile at retina density and 2x app zoom.
210 - snapshot: { width: 832, height: 448 },
211 -} as const;
212 -export type ComposerImageThumbnailMode = keyof typeof COMPOSER_THUMBNAIL_SIZES;
213 -const composerThumbnails = new WeakMap<
214 - File,
215 - Partial<Record<ComposerImageThumbnailMode, Promise<string | null>>>
216 ->();
217 -
218 -export function createComposerImageThumbnail(
219 - file: File,
220 - mode: ComposerImageThumbnailMode = "square",
221 -): Promise<string | null> {
222 - const fileThumbnails = composerThumbnails.get(file);
223 - const cached = fileThumbnails?.[mode];
207 +const composerThumbnails = new WeakMap<File, Promise<string | null>>();
208 +
209 +export function createComposerImageThumbnail(file: File): Promise<string | null> {
210 + const cached = composerThumbnails.get(file);
211 if (cached) return cached;
212 const thumbnail = (async () => {
213 if (!canRecompress()) return null;
214 let bitmap: ImageBitmap | undefined;
215 try {
216 bitmap = await createImageBitmap(file);
230 - if (bitmap.width <= 0 || bitmap.height <= 0) return null;
217 const side = Math.min(bitmap.width, bitmap.height);
232 - const sourceWidth = mode === "square" ? side : bitmap.width;
233 - const sourceHeight = mode === "square" ? side : bitmap.height;
234 - const bounds = COMPOSER_THUMBNAIL_SIZES[mode];
235 - const scale = Math.min(1, bounds.width / sourceWidth, bounds.height / sourceHeight);
236 - const width = Math.max(1, Math.round(sourceWidth * scale));
237 - const height = Math.max(1, Math.round(sourceHeight * scale));
238 - const surface = createCanvas(width, height);
218 + if (side <= 0) return null;
219 + const dimension = Math.min(256, side);
220 + const surface = createCanvas(dimension, dimension);
221 if (!surface) return null;
222 surface.context.drawImage(
223 bitmap,
242 - (bitmap.width - sourceWidth) / 2,
243 - (bitmap.height - sourceHeight) / 2,
244 - sourceWidth,
245 - sourceHeight,
224 + (bitmap.width - side) / 2,
225 + (bitmap.height - side) / 2,
226 + side,
227 + side,
228 0,
229 0,
248 - width,
249 - height,
230 + dimension,
231 + dimension,
232 );
233 const blob = await encodeCanvas(surface.canvas, 1, "image/png");
234 return blob ? await readFileAsDataUrl(blob) : null;
@@ -256,7 +238,7 @@ export function createComposerImageThumbnail(
238 bitmap?.close();
239 }
240 })();
259 - composerThumbnails.set(file, { ...fileThumbnails, [mode]: thumbnail });
241 + composerThumbnails.set(file, thumbnail);
242 return thumbnail;
243 }
244