Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(gfs): keep image previews click-only

Miguelon Peluchon7085d4557991
diff --git a/control-ui/app/constants/gfsFileThumbnail.ts b/control-ui/app/constants/gfsFileThumbnail.ts
deleted file mode 100644
index 1d339a6df..000000000
--- a/control-ui/app/constants/gfsFileThumbnail.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const GFS_FILE_THUMBNAIL_MAX_BYTES = 1 * 1024 * 1024
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index a18d23115..cc5788424 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -11528,14 +11528,6 @@ button.cu-gfs-tree__button:focus-visible,
border-radius: var(--cu-radius-sm);
}
-.cu-gfs-file-thumbnail {
- width: 100%;
- height: 100%;
- display: block;
- object-fit: cover;
- border-radius: var(--cu-radius-sm);
-}
-
.cu-gfs-list__meta {
color: var(--cu-text-muted);
font-size: 0.72rem;
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsx
index b70e97ebd..21f285151 100644
--- a/control-ui/components/GfsBrowser.tsx
+++ b/control-ui/components/GfsBrowser.tsx
@@ -2,7 +2,6 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { FileUploadModal } from '@components/FileUploadModal'
-import { GfsFileThumbnail } from '@components/GfsFileThumbnail'
import { GfsImagePreview } from '@components/GfsImagePreview'
import { GfsMarkdownPreview } from '@components/GfsMarkdownPreview'
import { GfsVideoPreview } from '@components/GfsVideoPreview'
@@ -702,11 +701,7 @@ export function GfsBrowser(): React.JSX.Element {
{child.kind === 'directory' ? (
<IconFolder />
) : gfsImagePreviewMimeType(child.name) ? (
- <GfsFileThumbnail
- byteLength={child.bytes}
- fileName={child.name}
- rid={child.rid}
- />
+ <IconImage />
) : isGfsVideoFile(child.name) ? (
<IconVideo />
) : isGfsDocumentFile(child.name) ? (
diff --git a/control-ui/components/GfsFileThumbnail/index.tsx b/control-ui/components/GfsFileThumbnail/index.tsx
deleted file mode 100644
index 08fc091ec..000000000
--- a/control-ui/components/GfsFileThumbnail/index.tsx
+++ /dev/null
@@ -1,97 +0,0 @@
-'use client'
-
-import { useEffect, useState } from 'react'
-import { IconImage } from '@components/Sidebar/icons'
-import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'
-import { gfsFetchFileBlob } from '@lib/api'
-import {
- getCachedGfsBlob,
- releaseCachedGfsBlob,
- retainCachedGfsBlob,
- setCachedGfsBlob,
-} from '@lib/gfsBlobCache'
-import { gfsImagePreviewMimeType } from '@lib/gfsImagePreview'
-import type { GfsFileThumbnailProps } from './types'
-
-/**
- * Tiny row-level thumbnail. Pulls the image blob through the existing
- * GFS proxy path, builds an object URL, and renders it inside the
- * row's existing 1.5rem icon slot. Falls back to the inline image
- * glyph when the row is over-budget or the blob fetch/load fails.
- *
- * The blob URL is published to the shared GfsBlobCache so the image
- * preview modal can open instantly if the user clicks the row.
- */
-export function GfsFileThumbnail({
- byteLength,
- fileName,
- rid,
-}: GfsFileThumbnailProps): React.JSX.Element {
- const shouldSkip = byteLength > GFS_FILE_THUMBNAIL_MAX_BYTES
- const [src, setSrc] = useState<string | null>(null)
- const [failed, setFailed] = useState(shouldSkip)
-
- useEffect(() => {
- if (shouldSkip) {
- setFailed(true)
- setSrc(null)
- return
- }
- const cached = getCachedGfsBlob(rid)
- if (cached && retainCachedGfsBlob(rid, cached.blobUrl)) {
- setSrc(cached.blobUrl)
- return () => releaseCachedGfsBlob(rid, cached.blobUrl)
- }
- let cancelled = false
- let objectUrl: string | null = null
-
- async function load(): Promise<void> {
- try {
- const fetched = await gfsFetchFileBlob(rid)
- if (cancelled) return
- if (fetched.size > GFS_FILE_THUMBNAIL_MAX_BYTES) {
- setFailed(true)
- return
- }
- // SVG (and other image) previews render through <img>, which
- // only paints the data when the object URL's blob carries the
- // right MIME type. The proxy may return application/octet-stream
- // for SVG bodies, so wrap with the type the image preview
- // modal already computes.
- const mimeType = gfsImagePreviewMimeType(fileName) ?? fetched.type
- const wrappedBlob =
- mimeType && mimeType !== fetched.type ? new Blob([fetched], { type: mimeType }) : fetched
- const cachedEntry = setCachedGfsBlob(rid, {
- blobUrl: URL.createObjectURL(wrappedBlob),
- mimeType: wrappedBlob.type,
- })
- objectUrl = cachedEntry.blobUrl
- setSrc(cachedEntry.blobUrl)
- } catch {
- if (!cancelled) setFailed(true)
- }
- }
-
- void load()
- return () => {
- cancelled = true
- if (objectUrl) releaseCachedGfsBlob(rid, objectUrl)
- }
- }, [fileName, rid, shouldSkip])
-
- if (failed || !src) {
- return <IconImage />
- }
-
- return (
- <img
- alt={`Thumbnail of ${fileName}`}
- className="cu-gfs-file-thumbnail"
- decoding="async"
- loading="lazy"
- src={src}
- />
- )
-}
-
-export type { GfsFileThumbnailProps } from './types'
diff --git a/control-ui/components/GfsFileThumbnail/types.ts b/control-ui/components/GfsFileThumbnail/types.ts
deleted file mode 100644
index c35afb951..000000000
--- a/control-ui/components/GfsFileThumbnail/types.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export interface GfsFileThumbnailProps {
- byteLength: number
- fileName: string
- rid: string
-}
diff --git a/control-ui/components/GfsImagePreview/index.tsx b/control-ui/components/GfsImagePreview/index.tsx
index ac95effa6..5ebca802d 100644
--- a/control-ui/components/GfsImagePreview/index.tsx
+++ b/control-ui/components/GfsImagePreview/index.tsx
@@ -7,12 +7,6 @@ import { useToast } from '@components/Toast'
import { IconX } from '@components/icons'
import { Button } from '@components/ui'
import { gfsFetchFileBlob } from '@lib/api'
-import {
- getCachedGfsBlob,
- releaseCachedGfsBlob,
- retainCachedGfsBlob,
- setCachedGfsBlob,
-} from '@lib/gfsBlobCache'
import { assertGfsImagePreviewSize } from '@lib/gfsImagePreview'
import type { GfsImagePreviewProps } from './types'
@@ -52,30 +46,6 @@ export function GfsImagePreview({
let objectUrl: string | null = null
async function loadPreview(): Promise<void> {
- // If the row thumbnail already paid the proxy round-trip for this
- // resource, reuse its object URL and skip the network entirely.
- const cached = getCachedGfsBlob(rid)
- if (cached && retainCachedGfsBlob(rid, cached.blobUrl)) {
- objectUrl = cached.blobUrl
- if (!active) return
- // Reconstruct the Blob from the same bytes the thumbnail cached
- // would require keeping the Blob alive; instead we copy the
- // cached object URL and let the modal revoke its own reference
- // when it unmounts (sharing the URL is fine — the browser keeps
- // the blob alive until every reference revokes).
- setPreviewUrl(cached.blobUrl)
- // The cached blob is reachable only through the object URL; for
- // the "Copy" affordance we still need a Blob. Issue a fetch on
- // the object URL to materialise it cheaply.
- try {
- const cachedBlob = await (await fetch(cached.blobUrl)).blob()
- if (active) setSourceBlob(cachedBlob)
- } catch {
- /* Copy will surface the error in copyImageToClipboard. */
- }
- return
- }
-
try {
assertGfsImagePreviewSize(byteLength)
const fetched = await gfsFetchFileBlob(rid)
@@ -83,14 +53,8 @@ export function GfsImagePreview({
if (!active) return
const blob = new Blob([fetched], { type: mimeType })
setSourceBlob(blob)
- const cachedEntry = setCachedGfsBlob(rid, {
- blobUrl: URL.createObjectURL(blob),
- mimeType: blob.type,
- })
- objectUrl = cachedEntry.blobUrl
- // Publish to the cache so the next preview open skips the network.
- // This preview holds one reference until its cleanup runs.
- setPreviewUrl(cachedEntry.blobUrl)
+ objectUrl = URL.createObjectURL(blob)
+ setPreviewUrl(objectUrl)
} catch (error) {
if (!active) return
setPreviewError(error instanceof Error ? error.message : 'Could not load the image preview')
@@ -100,9 +64,7 @@ export function GfsImagePreview({
void loadPreview()
return () => {
active = false
- // Release this preview's reference. The cache revokes the URL only
- // after the last thumbnail or preview consumer leaves.
- if (objectUrl) releaseCachedGfsBlob(rid, objectUrl)
+ if (objectUrl) URL.revokeObjectURL(objectUrl)
}
}, [byteLength, mimeType, rid])
diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsx
index ad340bcb1..76ebd3041 100644
--- a/control-ui/components/__tests__/GfsBrowser.test.tsx
+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx
@@ -247,28 +247,6 @@ describe('GfsBrowser', () => {
})
})
- it('reuses the row thumbnail blob when the user opens the image preview', async () => {
- mockApiGet.mockResolvedValueOnce({
- items: [child('logo.png', 'file', 7)],
- nextCursor: null,
- })
- mockGfsFetchFileBlob.mockResolvedValue(new Blob(['image-bytes']))
- renderBrowser()
-
- // Wait for the thumbnail to land so the cache is populated.
- await screen.findByAltText('Thumbnail of logo.png')
-
- // Clear the proxy call counter so we can assert the preview does
- // NOT touch gfsFetchFileBlob a second time.
- mockGfsFetchFileBlob.mockClear()
-
- fireEvent.click(screen.getByRole('button', { name: 'logo.png' }))
- const dialog = await screen.findByRole('dialog', { name: 'logo.png' })
- const img = await within(dialog).findByRole('img', { name: 'Preview of logo.png' })
- expect(img.getAttribute('src')).toBe('blob:gfs-image-preview')
- expect(mockGfsFetchFileBlob).not.toHaveBeenCalled()
- })
-
it('uses the paperclip header, labels the root as main, and ignores current-crumb clicks', async () => {
mockApiGet.mockResolvedValueOnce({ items: [], nextCursor: null })
renderBrowser()
@@ -580,6 +558,7 @@ describe('GfsBrowser', () => {
const previewTrigger = await screen.findByRole('button', { name: 'avatar.PNG' })
expect(screen.getByText('notes.bin').closest('button')).toBeNull()
+ expect(mockGfsFetchFileBlob).not.toHaveBeenCalled()
fireEvent.click(previewTrigger)
const dialog = await screen.findByRole('dialog', { name: 'avatar.PNG' })
@@ -588,8 +567,7 @@ describe('GfsBrowser', () => {
).toHaveAttribute('src', 'blob:gfs-image-preview')
expect(mockGfsFetchFileBlob).toHaveBeenCalledWith('r2')
// Preview modal wraps the fetched blob with the original MIME type so
- // the dialog <img> loads as that media type; the row thumbnail uses
- // the raw blob so it appears first in the createObjectURL log.
+ // the dialog <img> loads as that media type.
const previewCall = mockCreateObjectUrl.mock.calls.find(
call => (call[0] as Blob).type === 'image/png'
)
@@ -598,10 +576,7 @@ describe('GfsBrowser', () => {
const closeButton = within(dialog).getByRole('button', { name: /close image preview/i })
fireEvent.click(closeButton)
await waitFor(() => expect(screen.queryByRole('dialog', { name: 'avatar.PNG' })).toBeNull())
- // The thumbnail and the preview now share a cached object URL,
- // so the preview does NOT revoke on close (the row's thumbnail
- // owns the lifecycle). Verify the thumbnail-owned URL survives.
- expect(mockRevokeObjectUrl).not.toHaveBeenCalled()
+ expect(mockRevokeObjectUrl).toHaveBeenCalledWith('blob:gfs-image-preview')
await openResourceMenu('avatar.PNG')
fireEvent.click(screen.getByRole('menuitem', { name: 'Preview' }))
diff --git a/control-ui/components/__tests__/GfsFileThumbnail.test.tsx b/control-ui/components/__tests__/GfsFileThumbnail.test.tsx
deleted file mode 100644
index 061c49417..000000000
--- a/control-ui/components/__tests__/GfsFileThumbnail.test.tsx
+++ /dev/null
@@ -1,114 +0,0 @@
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { render, screen, waitFor } from '@testing-library/react'
-import { GfsFileThumbnail } from '../GfsFileThumbnail'
-import { ToastProvider } from '../Toast'
-
-const mockGfsFetchFileBlob = vi.fn()
-const mockCreateObjectUrl = vi.fn(() => 'blob:gfs-thumbnail')
-const mockRevokeObjectUrl = vi.fn()
-
-vi.mock('@lib/api', () => ({
- gfsFetchFileBlob: (...args: unknown[]) => mockGfsFetchFileBlob(...args),
-}))
-
-function renderThumb(props: Parameters<typeof GfsFileThumbnail>[0]) {
- return render(
- <ToastProvider>
- <GfsFileThumbnail {...props} />
- </ToastProvider>
- )
-}
-
-describe('GfsFileThumbnail', () => {
- beforeEach(() => {
- mockGfsFetchFileBlob.mockReset()
- mockCreateObjectUrl.mockReset()
- mockCreateObjectUrl.mockReturnValue('blob:gfs-thumbnail')
- mockRevokeObjectUrl.mockReset()
- Object.defineProperty(URL, 'createObjectURL', {
- configurable: true,
- value: mockCreateObjectUrl,
- })
- Object.defineProperty(URL, 'revokeObjectURL', {
- configurable: true,
- value: mockRevokeObjectUrl,
- })
- })
-
- afterEach(() => {
- vi.restoreAllMocks()
- })
-
- it('renders the inline image glyph for files larger than the thumbnail budget', () => {
- renderThumb({
- byteLength: 2 * 1024 * 1024,
- fileName: 'big.png',
- rid: 'r-big',
- })
- expect(screen.queryByRole('img')).toBeNull()
- expect(mockGfsFetchFileBlob).not.toHaveBeenCalled()
- })
-
- it('renders an <img> with the resolved blob URL once the proxy returns the bytes', async () => {
- mockGfsFetchFileBlob.mockResolvedValueOnce(new Blob(['fake-image-bytes']))
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-logo',
- })
-
- const img = await screen.findByAltText('Thumbnail of logo.png')
- expect(img.tagName).toBe('IMG')
- expect(img).toHaveAttribute('src', 'blob:gfs-thumbnail')
- expect(mockCreateObjectUrl).toHaveBeenCalledTimes(1)
- })
-
- it('releases the cached URL when the row unmounts so a remount fetches again', async () => {
- mockGfsFetchFileBlob.mockResolvedValue(new Blob(['fake-image-bytes']))
- const firstRender = renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-remount',
- })
-
- await screen.findByAltText('Thumbnail of logo.png')
- firstRender.unmount()
-
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-remount',
- })
-
- await waitFor(() => expect(mockGfsFetchFileBlob).toHaveBeenCalledTimes(2))
- expect(mockRevokeObjectUrl).toHaveBeenCalledWith('blob:gfs-thumbnail')
- })
-
- it('rewraps the blob with image/svg+xml when the proxy returns SVG bytes', async () => {
- const svgBytes = new Blob(['<svg></svg>'], { type: 'application/octet-stream' })
- mockGfsFetchFileBlob.mockResolvedValueOnce(svgBytes)
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.svg',
- rid: 'r-svg',
- })
-
- await screen.findByAltText('Thumbnail of logo.svg')
- expect(mockCreateObjectUrl).toHaveBeenCalledTimes(1)
- const blobArg = mockCreateObjectUrl.mock.calls[0]?.[0] as Blob
- expect(blobArg.type).toBe('image/svg+xml')
- })
-
- it('falls back to the image glyph when the proxy fetch rejects', async () => {
- mockGfsFetchFileBlob.mockRejectedValueOnce(new Error('boom'))
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-logo',
- })
-
- await waitFor(() => expect(mockGfsFetchFileBlob).toHaveBeenCalledTimes(1))
- expect(screen.queryByRole('img')).toBeNull()
- expect(mockCreateObjectUrl).not.toHaveBeenCalled()
- })
-})
diff --git a/control-ui/lib/gfsBlobCache.ts b/control-ui/lib/gfsBlobCache.ts
deleted file mode 100644
index 4db593be7..000000000
--- a/control-ui/lib/gfsBlobCache.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Tiny in-memory cache that lets the row thumbnail and the preview
- * modal share a single object URL for the same image bytes. Without
- * this the preview modal would re-fetch the same image every time it
- * opens, which dominates the "preview feels slow" complaint.
- *
- * The cache is module-scoped and survives navigation between folders while
- * a thumbnail or preview still references an entry. The last consumer
- * releases the object URL; window unload also releases any remaining URLs.
- */
-export type CachedGfsBlob = {
- blobUrl: string
- mimeType: string
-}
-
-type CacheEntry = CachedGfsBlob & {
- references: number
-}
-
-const blobUrlCache = new Map<string, CacheEntry>()
-
-export function getCachedGfsBlob(rid: string): CachedGfsBlob | null {
- return blobUrlCache.get(rid) ?? null
-}
-
-/**
- * Store a URL and claim its first owner. If another loader won the race for
- * this resource, retain that URL and release the newly-created one instead.
- */
-export function setCachedGfsBlob(rid: string, entry: CachedGfsBlob): CachedGfsBlob {
- const existing = blobUrlCache.get(rid)
- if (existing) {
- if (existing.blobUrl !== entry.blobUrl) URL.revokeObjectURL(entry.blobUrl)
- existing.references += 1
- return existing
- }
- const cacheEntry = { ...entry, references: 1 }
- blobUrlCache.set(rid, cacheEntry)
- return cacheEntry
-}
-
-export function retainCachedGfsBlob(rid: string, blobUrl: string): boolean {
- const entry = blobUrlCache.get(rid)
- if (!entry || entry.blobUrl !== blobUrl) return false
- entry.references += 1
- return true
-}
-
-export function releaseCachedGfsBlob(rid: string, blobUrl: string): void {
- const entry = blobUrlCache.get(rid)
- if (!entry || entry.blobUrl !== blobUrl) return
- entry.references -= 1
- if (entry.references > 0) return
- blobUrlCache.delete(rid)
- URL.revokeObjectURL(blobUrl)
-}
-
-export function clearCachedGfsBlob(rid: string, blobUrl?: string): void {
- const entry = blobUrlCache.get(rid)
- if (!entry || (blobUrl !== undefined && entry.blobUrl !== blobUrl)) return
- blobUrlCache.delete(rid)
-}
diff --git a/control-ui/lib/gfsFileThumbnail.ts b/control-ui/lib/gfsFileThumbnail.ts
deleted file mode 100644
index 1d63ce88e..000000000
--- a/control-ui/lib/gfsFileThumbnail.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'
-
-/**
- * Decide whether a row entry should render a small inline thumbnail
- * (currently image files only, and small enough to fetch cheaply).
- *
- * `bytes` is the metadata-declared size from the GFS listing. We use
- * the metadata size first so we can skip the request entirely when the
- * file is already known to be larger than the thumbnail budget; the
- * resolved blob is re-checked after fetch so oversized files don't
- * sneak through on stale metadata.
- */
-export function shouldRenderGfsFileThumbnail(opts: {
- isImage: boolean
- bytes: number
- maxBytes?: number
-}): boolean {
- if (!opts.isImage) return false
- const budget = opts.maxBytes ?? GFS_FILE_THUMBNAIL_MAX_BYTES
- return opts.bytes <= budget
-}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index cb12f538b..e1f64bb94 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.447",
+ "version": "0.1.448",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.447",
+ "version": "0.1.448",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index a389c6693..b9acd05fc 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.447",
+ "version": "0.1.448",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/desktop-app/ui/src/components/GfsFileIcon/index.tsx b/desktop-app/ui/src/components/GfsFileIcon/index.tsx
index 7025dcdd2..17b4e9bb8 100644
--- a/desktop-app/ui/src/components/GfsFileIcon/index.tsx
+++ b/desktop-app/ui/src/components/GfsFileIcon/index.tsx
@@ -1,4 +1,3 @@
-import { GfsFileThumbnail } from '@components/GfsFileThumbnail'
import {
IconAttachFile,
IconDocumentText,
@@ -12,18 +11,8 @@ import type { GfsFileIconProps } from './types'
export type { GfsFileIconProps } from './types'
-export function GfsFileIcon({ name, bytes, rid, ...iconProps }: GfsFileIconProps) {
- if (gfsImagePreviewMimeType(name)) {
- // Render the inline image thumbnail whenever we have a rid; the
- // component itself decides whether to fetch bytes or short-circuit
- // to the static icon when the file is over the thumbnail budget.
- if (rid !== undefined) {
- return (
- <GfsFileThumbnail byteLength={bytes ?? Number.MAX_SAFE_INTEGER} fileName={name} rid={rid} />
- )
- }
- return <IconImage {...iconProps} />
- }
+export function GfsFileIcon({ name, ...iconProps }: GfsFileIconProps) {
+ if (gfsImagePreviewMimeType(name)) return <IconImage {...iconProps} />
if (isGfsVideoFile(name)) return <IconVideo {...iconProps} />
if (isGfsDocumentFile(name)) return <IconDocumentText {...iconProps} />
return <IconAttachFile {...iconProps} />
diff --git a/desktop-app/ui/src/components/GfsFileIcon/types.ts b/desktop-app/ui/src/components/GfsFileIcon/types.ts
index 2230a59d7..0a6e92c7b 100644
--- a/desktop-app/ui/src/components/GfsFileIcon/types.ts
+++ b/desktop-app/ui/src/components/GfsFileIcon/types.ts
@@ -2,20 +2,4 @@ import type { SVGProps } from 'react'
export type GfsFileIconProps = {
name: string
-} & (
- | {
- /**
- * Provide `bytes` + `rid` to render an inline image thumbnail
- * (still shown as a 24×24 square, just painted with the actual
- * image bytes instead of the image glyph). Missing either field
- * falls back to the static image glyph.
- */
- bytes: number
- rid: string
- }
- | {
- bytes?: never
- rid?: never
- }
-) &
- SVGProps<SVGSVGElement>
+} & SVGProps<SVGSVGElement>
diff --git a/desktop-app/ui/src/components/GfsFileThumbnail/index.tsx b/desktop-app/ui/src/components/GfsFileThumbnail/index.tsx
deleted file mode 100644
index d2f475fce..000000000
--- a/desktop-app/ui/src/components/GfsFileThumbnail/index.tsx
+++ /dev/null
@@ -1,88 +0,0 @@
-import { useEffect, useState } from 'react'
-import { IconImage } from '@components/SidebarNav/icons'
-import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'
-import {
- getCachedGfsBlob,
- releaseCachedGfsBlob,
- retainCachedGfsBlob,
- setCachedGfsBlob,
-} from '@lib/gfsBlobCache'
-import { gfsImagePreviewMimeType } from '@lib/gfsImagePreview'
-import type { GfsFileThumbnailProps } from './types'
-
-/**
- * Tiny row-level thumbnail. Pulls the image blob through the existing
- * GFS download path, builds an object URL, and renders it inside the
- * row's existing icon slot. Falls back to the inline image glyph when
- * the row is over-budget or the blob fetch/load fails.
- *
- * The blob URL is published to the shared GfsBlobCache so the image
- * preview modal can open instantly if the user clicks the row.
- */
-export function GfsFileThumbnail({ byteLength, fileName, rid }: GfsFileThumbnailProps) {
- const shouldSkip = byteLength > GFS_FILE_THUMBNAIL_MAX_BYTES
- const [src, setSrc] = useState<string | null>(null)
- const [failed, setFailed] = useState(shouldSkip)
-
- useEffect(() => {
- if (shouldSkip) {
- setFailed(true)
- setSrc(null)
- return
- }
- const cached = getCachedGfsBlob(rid)
- if (cached && retainCachedGfsBlob(rid, cached.blobUrl)) {
- setSrc(cached.blobUrl)
- return () => releaseCachedGfsBlob(rid, cached.blobUrl)
- }
- let cancelled = false
- let objectUrl: string | null = null
-
- const load = async () => {
- try {
- const { bytes } = await window.clerum.gfs.download(rid)
- if (cancelled) return
- if (bytes.byteLength > GFS_FILE_THUMBNAIL_MAX_BYTES) {
- setFailed(true)
- return
- }
- // SVG thumbnails need image/svg+xml on the object URL, but the
- // download IPC can hand us application/octet-stream. Wrap the
- // bytes with the type the preview modal already computes so the
- // <img> can actually paint the SVG.
- const mimeType = gfsImagePreviewMimeType(fileName)
- const blob = mimeType !== null ? new Blob([bytes], { type: mimeType }) : new Blob([bytes])
- const cachedEntry = setCachedGfsBlob(rid, {
- blobUrl: URL.createObjectURL(blob),
- mimeType: blob.type,
- })
- objectUrl = cachedEntry.blobUrl
- setSrc(cachedEntry.blobUrl)
- } catch {
- if (!cancelled) setFailed(true)
- }
- }
-
- void load()
- return () => {
- cancelled = true
- if (objectUrl) releaseCachedGfsBlob(rid, objectUrl)
- }
- }, [fileName, rid, shouldSkip])
-
- if (failed || !src) {
- return <IconImage />
- }
-
- return (
- <img
- alt={`Thumbnail of ${fileName}`}
- className="da-gfs-file-thumbnail"
- decoding="async"
- loading="lazy"
- src={src}
- />
- )
-}
-
-export type { GfsFileThumbnailProps } from './types'
diff --git a/desktop-app/ui/src/components/GfsFileThumbnail/types.ts b/desktop-app/ui/src/components/GfsFileThumbnail/types.ts
deleted file mode 100644
index 1f6b5fd80..000000000
--- a/desktop-app/ui/src/components/GfsFileThumbnail/types.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export type GfsFileThumbnailProps = {
- byteLength: number
- fileName: string
- rid: string
-}
diff --git a/desktop-app/ui/src/components/GfsImagePreview/index.tsx b/desktop-app/ui/src/components/GfsImagePreview/index.tsx
index 26b5ce27f..d673dbb51 100644
--- a/desktop-app/ui/src/components/GfsImagePreview/index.tsx
+++ b/desktop-app/ui/src/components/GfsImagePreview/index.tsx
@@ -2,12 +2,6 @@ import { useEffect, useId, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import { IconButton, StatusBanner } from '@components/Common'
import { IconClose, IconCopy } from '@components/SidebarNav/icons'
-import {
- getCachedGfsBlob,
- releaseCachedGfsBlob,
- retainCachedGfsBlob,
- setCachedGfsBlob,
-} from '@lib/gfsBlobCache'
import { assertGfsImagePreviewSize } from '@lib/gfsImagePreview'
import type { GfsImagePreviewProps } from './types'
@@ -27,10 +21,6 @@ export function GfsImagePreview({
const [copyState, setCopyState] = useState<'idle' | 'copied' | 'error'>('idle')
const copyResetTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
- // Translate gfs://<drive>/<rid> to a stable cache key so we can share
- // the row thumbnail's blob URL with this preview modal.
- const cacheKey = gfsUriCacheKey(gfsUri)
-
useEffect(() => {
closeButtonRef.current?.focus()
const handleKeyDown = (event: KeyboardEvent) => {
@@ -45,25 +35,6 @@ export function GfsImagePreview({
let objectUrl: string | null = null
const loadPreview = async () => {
- // If the row thumbnail already paid the proxy round-trip for this
- // resource, reuse its object URL and skip the network entirely.
- const cached = getCachedGfsBlob(cacheKey)
- if (cached && retainCachedGfsBlob(cacheKey, cached.blobUrl)) {
- objectUrl = cached.blobUrl
- if (!active) return
- setPreviewUrl(cached.blobUrl)
- // The cached blob is reachable only through the object URL; for
- // the "Copy" affordance we still need a Blob. Issue a fetch on
- // the object URL to materialise it cheaply.
- try {
- const cachedBlob = await (await fetch(cached.blobUrl)).blob()
- if (active) setSourceBlob(cachedBlob)
- } catch {
- /* Copy will surface the error in copyImageToClipboard. */
- }
- return
- }
-
try {
assertGfsImagePreviewSize(byteLength)
const { bytes } = await window.clerum.gfs.download(gfsUri)
@@ -71,14 +42,8 @@ export function GfsImagePreview({
if (!active) return
const blob = new Blob([bytes], { type: mimeType })
setSourceBlob(blob)
- const cachedEntry = setCachedGfsBlob(cacheKey, {
- blobUrl: URL.createObjectURL(blob),
- mimeType: blob.type,
- })
- objectUrl = cachedEntry.blobUrl
- // Publish to the cache so the next preview open skips the network.
- // This preview holds one reference until its cleanup runs.
- setPreviewUrl(cachedEntry.blobUrl)
+ objectUrl = URL.createObjectURL(blob)
+ setPreviewUrl(objectUrl)
} catch (error) {
if (!active) return
onDownloadError?.(error)
@@ -89,11 +54,9 @@ export function GfsImagePreview({
void loadPreview()
return () => {
active = false
- // Release this preview's reference. The cache revokes the URL only
- // after the last thumbnail or preview consumer leaves.
- if (objectUrl) releaseCachedGfsBlob(cacheKey, objectUrl)
+ if (objectUrl) URL.revokeObjectURL(objectUrl)
}
- }, [byteLength, cacheKey, gfsUri, mimeType, onDownloadError])
+ }, [byteLength, gfsUri, mimeType, onDownloadError])
useEffect(() => {
return () => {
@@ -192,13 +155,6 @@ export function GfsImagePreview({
)
}
-/** Strip the `gfs://<drive>/` prefix to expose just the resource id,
- * which is the same key the row thumbnail uses for the blob cache. */
-function gfsUriCacheKey(gfsUri: string): string {
- const slash = gfsUri.lastIndexOf('/')
- return slash >= 0 ? gfsUri.slice(slash + 1) : gfsUri
-}
-
async function convertBlobToPng(blob: Blob): Promise<Blob | null> {
if (typeof createImageBitmap === 'undefined') return null
try {
diff --git a/desktop-app/ui/src/components/__tests__/GfsFileThumbnail.test.tsx b/desktop-app/ui/src/components/__tests__/GfsFileThumbnail.test.tsx
deleted file mode 100644
index df9afda0f..000000000
--- a/desktop-app/ui/src/components/__tests__/GfsFileThumbnail.test.tsx
+++ /dev/null
@@ -1,121 +0,0 @@
-// @vitest-environment jsdom
-// @vitest-environment jsdom
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, render, screen, waitFor } from '@testing-library/react'
-import { clearCachedGfsBlob } from '@lib/gfsBlobCache'
-import { GfsFileThumbnail } from '../GfsFileThumbnail'
-
-const mockDownload = vi.fn()
-const mockCreateObjectUrl = vi.fn(() => 'blob:gfs-thumbnail')
-const mockRevokeObjectUrl = vi.fn()
-
-function renderThumb(props: Parameters<typeof GfsFileThumbnail>[0]) {
- return render(<GfsFileThumbnail {...props} />)
-}
-
-describe('GfsFileThumbnail', () => {
- beforeEach(() => {
- mockDownload.mockReset()
- clearCachedGfsBlob('r-logo')
- clearCachedGfsBlob('r-svg')
- mockCreateObjectUrl.mockReset()
- mockCreateObjectUrl.mockReturnValue('blob:gfs-thumbnail')
- mockRevokeObjectUrl.mockReset()
- Object.defineProperty(URL, 'createObjectURL', {
- configurable: true,
- value: mockCreateObjectUrl,
- })
- Object.defineProperty(URL, 'revokeObjectURL', {
- configurable: true,
- value: mockRevokeObjectUrl,
- })
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: { gfs: { download: mockDownload } },
- })
- })
-
- afterEach(async () => {
- cleanup()
- await new Promise(resolve => setTimeout(resolve, 0))
- vi.restoreAllMocks()
- })
-
- it('renders the inline image glyph when the file exceeds the thumbnail budget', () => {
- renderThumb({
- byteLength: 2 * 1024 * 1024,
- fileName: 'big.png',
- rid: 'r-big',
- })
- expect(screen.queryByRole('img')).toBeNull()
- expect(mockDownload).not.toHaveBeenCalled()
- })
-
- it('renders an <img> with the resolved blob URL once the download returns', async () => {
- mockDownload.mockResolvedValueOnce({ bytes: new Uint8Array([1, 2, 3, 4]).buffer })
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-logo',
- })
-
- const img = await screen.findByAltText('Thumbnail of logo.png')
- expect(img.tagName).toBe('IMG')
- expect(img.getAttribute('src')).toBe('blob:gfs-thumbnail')
- expect(mockCreateObjectUrl).toHaveBeenCalledTimes(1)
- })
-
- it('releases the cached URL when the row unmounts so a remount fetches again', async () => {
- mockDownload.mockResolvedValue({ bytes: new Uint8Array([1, 2, 3, 4]).buffer })
- const firstRender = renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-remount',
- })
-
- await screen.findByAltText('Thumbnail of logo.png')
- firstRender.unmount()
-
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-remount',
- })
-
- await waitFor(() => expect(mockDownload).toHaveBeenCalledTimes(2))
- expect(mockRevokeObjectUrl).toHaveBeenCalledWith('blob:gfs-thumbnail')
- })
-
- it('rewraps the blob with image/svg+xml when the download returns SVG bytes', async () => {
- const svgBytes = new TextEncoder().encode('<svg></svg>').buffer
- mockDownload.mockResolvedValueOnce({ bytes: svgBytes })
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.svg',
- rid: 'r-svg',
- })
-
- await screen.findByAltText('Thumbnail of logo.svg')
- expect(mockCreateObjectUrl).toHaveBeenCalledTimes(1)
- const blobArg = mockCreateObjectUrl.mock.calls[0]?.[0] as Blob
- expect(blobArg.type).toBe('image/svg+xml')
- })
-
- it('falls back to the image glyph when the download rejects', async () => {
- let rejectDownload: (() => void) | undefined
- const slowDownload = new Promise<{ bytes: ArrayBuffer }>((_, reject) => {
- rejectDownload = () => reject(new Error('boom'))
- })
- mockDownload.mockReturnValueOnce(slowDownload)
- renderThumb({
- byteLength: 64 * 1024,
- fileName: 'logo.png',
- rid: 'r-logo',
- })
-
- await waitFor(() => expect(mockDownload).toHaveBeenCalledTimes(1))
- rejectDownload?.()
- await waitFor(() => expect(mockCreateObjectUrl).not.toHaveBeenCalled())
- expect(screen.queryByAltText('Thumbnail of logo.png')).toBeNull()
- })
-})
diff --git a/desktop-app/ui/src/constants/gfsFileThumbnail.ts b/desktop-app/ui/src/constants/gfsFileThumbnail.ts
deleted file mode 100644
index 1d339a6df..000000000
--- a/desktop-app/ui/src/constants/gfsFileThumbnail.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const GFS_FILE_THUMBNAIL_MAX_BYTES = 1 * 1024 * 1024
diff --git a/desktop-app/ui/src/lib/gfsBlobCache.ts b/desktop-app/ui/src/lib/gfsBlobCache.ts
deleted file mode 100644
index 4db593be7..000000000
--- a/desktop-app/ui/src/lib/gfsBlobCache.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Tiny in-memory cache that lets the row thumbnail and the preview
- * modal share a single object URL for the same image bytes. Without
- * this the preview modal would re-fetch the same image every time it
- * opens, which dominates the "preview feels slow" complaint.
- *
- * The cache is module-scoped and survives navigation between folders while
- * a thumbnail or preview still references an entry. The last consumer
- * releases the object URL; window unload also releases any remaining URLs.
- */
-export type CachedGfsBlob = {
- blobUrl: string
- mimeType: string
-}
-
-type CacheEntry = CachedGfsBlob & {
- references: number
-}
-
-const blobUrlCache = new Map<string, CacheEntry>()
-
-export function getCachedGfsBlob(rid: string): CachedGfsBlob | null {
- return blobUrlCache.get(rid) ?? null
-}
-
-/**
- * Store a URL and claim its first owner. If another loader won the race for
- * this resource, retain that URL and release the newly-created one instead.
- */
-export function setCachedGfsBlob(rid: string, entry: CachedGfsBlob): CachedGfsBlob {
- const existing = blobUrlCache.get(rid)
- if (existing) {
- if (existing.blobUrl !== entry.blobUrl) URL.revokeObjectURL(entry.blobUrl)
- existing.references += 1
- return existing
- }
- const cacheEntry = { ...entry, references: 1 }
- blobUrlCache.set(rid, cacheEntry)
- return cacheEntry
-}
-
-export function retainCachedGfsBlob(rid: string, blobUrl: string): boolean {
- const entry = blobUrlCache.get(rid)
- if (!entry || entry.blobUrl !== blobUrl) return false
- entry.references += 1
- return true
-}
-
-export function releaseCachedGfsBlob(rid: string, blobUrl: string): void {
- const entry = blobUrlCache.get(rid)
- if (!entry || entry.blobUrl !== blobUrl) return
- entry.references -= 1
- if (entry.references > 0) return
- blobUrlCache.delete(rid)
- URL.revokeObjectURL(blobUrl)
-}
-
-export function clearCachedGfsBlob(rid: string, blobUrl?: string): void {
- const entry = blobUrlCache.get(rid)
- if (!entry || (blobUrl !== undefined && entry.blobUrl !== blobUrl)) return
- blobUrlCache.delete(rid)
-}
diff --git a/desktop-app/ui/src/lib/gfsFileThumbnail.ts b/desktop-app/ui/src/lib/gfsFileThumbnail.ts
deleted file mode 100644
index 17df48fbc..000000000
--- a/desktop-app/ui/src/lib/gfsFileThumbnail.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'
-
-/**
- * Decide whether a row entry should render a small inline thumbnail
- * (currently image files only, and small enough to fetch cheaply).
- *
- * `bytes` is the metadata-declared size from the GFS listing. We use
- * the metadata size first so we can skip the request entirely when the
- * file is already known to be larger than the thumbnail budget.
- */
-export function shouldRenderGfsFileThumbnail(opts: {
- isImage: boolean
- bytes: number
- maxBytes?: number
-}): boolean {
- if (!opts.isImage) return false
- const budget = opts.maxBytes ?? GFS_FILE_THUMBNAIL_MAX_BYTES
- return opts.bytes <= budget
-}
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index 50ab5a116..f1e22f705 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -739,11 +739,7 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
) : currentIsFile ? (
<div className="da-gfs-current-file">
<span className="da-gfs-current-file__icon" aria-hidden="true">
- {currentIsFile ? (
- <GfsFileIcon name={current.name} bytes={current.bytes} rid={current.rid} />
- ) : (
- <IconAttachFile />
- )}
+ {currentIsFile ? <GfsFileIcon name={current.name} /> : <IconAttachFile />}
</span>
<div className="da-gfs-current-file__copy">
<div className="da-gfs-current-file__title-row">
@@ -821,11 +817,7 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
{resource.kind === 'directory' ? (
<IconContexts />
) : (
- <GfsFileIcon
- name={resource.name}
- bytes={resource.bytes}
- rid={resource.rid}
- />
+ <GfsFileIcon name={resource.name} />
)}
</span>
<span className="da-gfs-list__identity da-grid__cell">
@@ -976,11 +968,7 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
className={`da-gfs-manage-dialog__icon${currentIsFolder ? ' da-gfs-manage-dialog__icon--folder' : ''}`}
aria-hidden="true"
>
- {currentIsFolder ? (
- <IconContexts />
- ) : (
- <GfsFileIcon name={current.name} bytes={current.bytes} rid={current.rid} />
- )}
+ {currentIsFolder ? <IconContexts /> : <GfsFileIcon name={current.name} />}
</span>
<span className="da-gfs-manage-dialog__heading">
{renameOpen ? (
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index 3dcd13f76..48bcbe48b 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -1614,27 +1614,18 @@ describe('FilesPage', () => {
})
renderFilesPage()
- // Wait for the row thumbnail to land so the blob cache is warm
- // before the user opens the preview modal.
- await screen.findByAltText('Thumbnail of diagram.PNG')
-
- // Capture download calls made by the thumbnail so we can assert
- // that opening the preview doesn't trigger another fetch.
- const downloadCallsAfterThumbnail = download.mock.calls.length
+ expect(download).not.toHaveBeenCalled()
fireEvent.click(screen.getByRole('button', { name: 'diagram.PNG' }))
const dialog = await screen.findByRole('dialog', { name: 'diagram.PNG' })
await waitFor(() => expect(within(dialog).getByAltText('Preview of diagram.PNG')).toBeTruthy())
- // The preview reuses the cached object URL — the proxy download
- // is NOT triggered a second time.
- expect(download.mock.calls.length).toBe(downloadCallsAfterThumbnail)
+ expect(download).toHaveBeenCalledWith('gfs://main/image-1')
+ expect(download).toHaveBeenCalledTimes(1)
expect(anchorClick).not.toHaveBeenCalled()
fireEvent.click(within(dialog).getByRole('button', { name: 'Close image preview' }))
await waitFor(() => expect(screen.queryByRole('dialog', { name: 'diagram.PNG' })).toBeNull())
- // The thumbnail owns the cached URL lifecycle, so closing the
- // preview must NOT revoke the object URL.
- expect(revokeObjectURL).not.toHaveBeenCalled()
+ expect(revokeObjectURL).toHaveBeenCalledWith('blob:gfs-image-preview')
})
it('copies markdown source to the clipboard via the preview header button', async () => {
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 4f161c7e7..07f0b4f26 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -13467,18 +13467,11 @@ pre {
overflow: hidden;
}
-.da-gfs-list__icon svg,
-.da-gfs-list__icon .da-gfs-file-thumbnail {
+.da-gfs-list__icon svg {
width: 100%;
height: 100%;
}
-.da-gfs-file-thumbnail {
- display: block;
- object-fit: cover;
- border-radius: var(--radius-sm);
-}
-
.da-gfs-list__identity {
display: grid;
gap: var(--space-0-5);