Repository navigation
Description
Problem
On a fresh page load, compact preview thumbnails take a couple of seconds to appear in task lists, goals and the Inbox. Each thumbnail re-downloads the full-resolution capture and re-runs the multi-pass canvas downsampling (downsampleToCanvas in previewDownsampling.ts) on the main thread.
Two causes on main:
- Every load refetches the full image. Task and goal previews are rewritten to ProPR's authenticated media route (
/api/preview-media/{pulls|comments}/:owner/:repo/:number/:assetId, seeprojectApplicationMediainpackages/api/services/previewMediaProjection.ts). The UI loads them as same-origin blobs (usePreviewMediaSource). The route responds withCache-Control: private, no-store, so the browser cache never helps, and the API itself fetches the asset from GitHub on each request. - Every load re-downsamples. Nothing persists the downsampled result.
Hard constraint (learned in #2502)
Direct https://github.com/user-attachments/assets/<id> URLs redirect to S3 without CORS headers. A canvas that draws them is tainted and can't be exported with toDataURL/toBlob, and createImageBitmap doesn't get around it. Client-side thumbnail caching is only possible for same-origin sources, meaning previews served through /api/preview-media/... as blobs. Don't attempt CORS probes or no-cors fallbacks.
Proposal
- Persist downsampled thumbnails for same-origin sources. After
PreviewImagedownsamples a blob-backed preview, store the result (WebP or PNG blob plus dimensions) in IndexedDB. On the next mount, paint from the cache before fetching or decoding anything.- Key: account/desktop scope + media URL + CSS width × height + device pixel ratio. Use the same scope key
usePreviewMediaSourcealready uses, so a cached thumbnail never crosses accounts or desktop profiles. - TTL: 7 days. Prune expired entries at idle, cap total entries or bytes, and clear the account's entries on logout and account switch.
- If IndexedDB is unavailable (private mode or blocked), fall back to an in-memory map without failing.
- On a cache hit, skip
usePreviewMediaSource's full-size fetch entirely for compact thumbnails. Fetch the original only when the user opens the full view or lightbox.
- Key: account/desktop scope + media URL + CSS width × height + device pixel ratio. Use the same scope key
- Let the browser cache the media route privately. GitHub user-attachment asset IDs are immutable, so
/api/preview-media/...can returnCache-Control: private, max-age=86400, or something similar, instead ofno-store. That speeds up the full view too. KeepVary: Authorization, Cookie, and confirm that revoking access is acceptable within the max-age window. If it isn't, keepno-storeand rely on step 1. - Check coverage. Confirm that every surface rendering compact thumbnails (task list, task detail, goals, Inbox, dashboard) receives projected
/api/preview-media/...URLs. Where a surface still gets raw GitHub URLs, extend the projection rather than adding client workarounds. Previews that stay on raw GitHub URLs keep today's behavior.
Acceptance criteria
- On a second load of a task list, goal or Inbox view, compact thumbnails paint from the cache, with no media fetch and no downsampling passes. Verify with a component or browser test that counts fetches and halving passes.
- A cached thumbnail is never shown under a different account or desktop profile, and logout clears that account's entries.
- Expired entries are ignored and pruned. Storage stays within the cap.
- Raw GitHub-URL previews keep working; nothing tries to export a tainted canvas.
- The full view and lightbox still load the original image.
Out of scope
Service-worker caching of opaque GitHub responses (#2502's final design). It skips the network fetch but still decodes and downsamples on every load, and it can't cache the thumbnail itself.
Activity
propr-dev commentedon Sep 23, 2026
Suggested Implementation:
// ============================================
// Part 1: Cache downsampled canvas preview images locally with 1-week expiration
// ============================================
Implementation Approach
We implemented a two-tier caching architecture (L1 in-memory
Map+ L2IndexedDB) specifically tailored for high-resolution canvas thumbnails:QuotaExceededErrorand blocks the main thread during serialization. IndexedDB provides asynchronous, non-blocking storage with generous quotas (typically hundreds of megabytes) and structured indexing.(url, targetWidth, targetHeight, ratio): Preview thumbnails are displayed in different contexts: 24x24 micro rows, 64x48 mobile cards, and 80x56 desktop rows. In addition, displays differ bydevicePixelRatio(1x standard vs 2x Retina). Keying by both dimensions and pixel density ensures each used size maintains crisp, artifact-free contain-fit proportions without distortion.timestamp. Lookups checkDate.now() - timestamp > PREVIEW_CACHE_TTL_MS(7 days) and reject expired entries. Additionally, an index ontimestampallows fast range deletion (IDBKeyRange.upperBound) during DB initialization without scanning the whole dataset.canvas.toDataURL()can throw aSecurityError. All cache writes are wrapped in safe guards so export failures simply leave the canvas un-persisted while displaying normally.File:
propr-ui/src/components/previewCache.tsWhy this file: This is the core module managing local thumbnail persistence, cache key generation, expiration checks, IndexedDB lifecycle, and canvas image serialization/deserialization. Creating a standalone module isolates storage concerns from React component rendering and allows independent unit testing.
File:
propr-ui/src/components/PreviewMedia.tsxWhy this file:
PreviewImageis the React component responsible for rendering preview thumbnails. We modify it to query the local cache as soon as target layout dimensions are established, rendering the cached image immediately without waiting for the original 4K image to load or executing the CPU-heavy downsampling algorithm. We also record the rendered size to avoid redundant redraws when the native image eventually loads in the background.File:
propr-ui/src/components/PreviewMedia.test.tsxWhy this file: We extend the test suite to verify the local caching contract: deterministic key generation across dimensions and display pixel ratios, storage and retrieval of cached records, enforcement of the 1-week expiration cutoff, canvas export serialization, and rendering to target contexts.
// ============================================
// Part 2: Cache downsampled canvas preview images locally with 1-week expiration
// ============================================
Implementation Approach
We implemented a two-tier caching architecture (L1 in-memory
Map+ L2IndexedDB) specifically tailored for high-resolution canvas thumbnails:QuotaExceededErrorand blocks the main thread during serialization. IndexedDB provides asynchronous, non-blocking storage with generous quotas (typically hundreds of megabytes) and structured indexing.(url, targetWidth, targetHeight, ratio): Preview thumbnails are displayed in different contexts: 24x24 micro rows, 64x48 mobile cards, and 80x56 desktop rows. In addition, displays differ bydevicePixelRatio(1x standard vs 2x Retina). Keying by both dimensions and pixel density ensures each used size maintains crisp, artifact-free contain-fit proportions without distortion.timestamp. Lookups checkDate.now() - timestamp > PREVIEW_CACHE_TTL_MS(7 days) and reject expired entries. Additionally, an index ontimestampallows fast range deletion (IDBKeyRange.upperBound) during DB initialization without scanning the whole dataset.canvas.toDataURL()can throw aSecurityError. All cache writes are wrapped in safe guards so export failures simply leave the canvas un-persisted while displaying normally.File:
propr-ui/src/components/previewCache.tsWhy this file: This is the core module managing local thumbnail persistence, cache key generation, expiration checks, IndexedDB lifecycle, and canvas image serialization/deserialization. Creating a standalone module isolates storage concerns from React component rendering and allows independent unit testing.
File:
propr-ui/src/components/PreviewMedia.tsxWhy this file:
PreviewImageis the React component responsible for rendering preview thumbnails. We modify it to query the local cache as soon as target layout dimensions are established, rendering the cached image immediately without waiting for the original 4K image to load or executing the CPU-heavy downsampling algorithm. We also record the rendered size to avoid redundant redraws when the native image eventually loads in the background.File:
propr-ui/src/components/PreviewMedia.test.tsxWhy this file: We extend the test suite to verify the local caching contract: deterministic key generation across dimensions and display pixel ratios, storage and retrieval of cached records, enforcement of the 1-week expiration cutoff, canvas export serialization, and rendering to target contexts.
propr-dev commentedon Sep 23, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-52500/claude-opus-5-cache-downsampled-canvas--20260923-1611-2mhmainissue-2500-20260923-1611-claude-opus-5-2mh🔍 Track Task Execution
feat(ai): F1 is addressed, plus one finding you should know about bef…
[-]Cache downsampled canvas preview images locally with 1-week expiration and Cache downsampled canvas preview images locally with 1-week expiration[/-][+]Cache downsampled preview thumbnails for same-origin preview media[/+]