Skip to content

fix(presentation): pass absolute URLs through getPreviewThumbnail - #11014

Open
clayrisser wants to merge 1 commit into
hcengineering:developfrom
clayrisser:fix/preview-thumbnail-absolute-url
Open

fix(presentation): pass absolute URLs through getPreviewThumbnail#11014
clayrisser wants to merge 1 commit into
hcengineering:developfrom
clayrisser:fix/preview-thumbnail-absolute-url

Conversation

@clayrisser

Copy link
Copy Markdown

Problem

packages/presentation has three functions that turn a blob ref into a URL, and they disagree about what to do when the ref is already an absolute URL.

getFileUrl (file.ts:55) passes it through:

if (file.includes('://')) {
  return file
}

blobToSrcSet (preview.ts:52) also recognises it, and returns '' — correctly, because there is no srcset to build for an external URL.

getPreviewThumbnail (preview.ts:92) has no guard at all:

export function getPreviewThumbnail (file: string, width: number, height: number, dpr?: number): string {
  return getImagePreviewUrl(
    encodeURIComponent(getCurrentWorkspaceUuid()),
    encodeURIComponent(file),
    

So an absolute URL is percent-encoded and pasted into the preview service's path, producing something like:

https://preview.example.com/image/fit=cover,width=100,height=200,dpr=2/<ws>/https%3A%2F%2Fcdn.example.com%2Fcover.png

which is not a thumbnail of anything.

Fix

Add the passthrough, matching getFileUrl — a thumbnail needs a usable src, so passthrough rather than blobToSrcSet's empty string is the right analogue:

 export function getPreviewThumbnail (file: string, width: number, height: number, dpr?: number): string {
+  // Absolute URLs pass through unchanged, same as getFileUrl (blobToSrcSet
+  // guards on '://' too but returns '' — a thumbnail src wants the passthrough)
+  if (file.includes('://')) {
+    return file
+  }
+
   return getImagePreviewUrl(

Verification

Five cases in packages/presentation/src/___tests___/preview.test.ts, alongside the four suites already in that directory:

  • a plain blob id is routed through the preview service
  • a blob id needing percent-encoding is still encoded (so the guard does not change the normal path)
  • an absolute URL passes through byte-for-byte
  • an absolute URL with a query string passes through byte-for-byte
  • getPreviewThumbnail agrees with getSrcSet about what counts as an absolute ref

The last one is the point of the change rather than a restatement of it: the three functions disagreeing is the actual defect, and that case pins them together. Three of the five fail with the guard removed.

⚠️ These tests will not run in CI as things stand. packages/presentation has jest.config.js, the jest devDependencies, and four existing suites, but no test / _phase:test script — and rush's phases are declared ignoreMissingScript: true, so the whole package is skipped silently. I have opened that separately as a one-line-per-package build change. Either land that first, or fold those two lines into this PR — happy either way, just say which you prefer.

Verified against develop @ 1be6047c8: getFileUrl's guard at file.ts:55 and blobToSrcSet's at preview.ts:52 are both still there, getPreviewThumbnail at :92 still has none.

Note on scope

This was originally prepared together with three unrelated error-handling fixes on the same read path (a TextViewer fetch with no try/catch, an ImageViewer <img> with no on:error, and an embed nodeview promise with no .catch). I have split those into a separate PR, since they are a different concern and mixing them would make both harder to review.

getFileUrl (file.ts:55) returns absolute-URL blob refs unchanged and
blobToSrcSet (preview.ts:52) recognises them too, but getPreviewThumbnail
had no '://' guard and percent-encoded the whole URL into the preview
service's path, producing a thumbnail URL for nothing. Add the
passthrough, getFileUrl's analog, since a thumbnail needs a usable src.

Tests: five cases in packages/presentation/src/___tests___/preview.test.ts,
three of which fail with the guard removed. Note they do not run yet --
the package has no test phase script; see the companion build change.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Clay Risser <clayrisser@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@clayrisser
clayrisser force-pushed the fix/preview-thumbnail-absolute-url branch from d24bc40 to c78fe58 Compare August 13, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant