Skip to content

Fix double-prefixed image preview URL when editing an existing item - #30

Merged
kiran-brahma merged 1 commit into
mainfrom
fix/double-prefixed-image-url
Jul 8, 2026
Merged

Fix double-prefixed image preview URL when editing an existing item#30
kiran-brahma merged 1 commit into
mainfrom
fix/double-prefixed-image-url

Conversation

@kiran-brahma

Copy link
Copy Markdown
Owner

Summary

On the Home Page hero image (and any image field on an existing item), the admin editor's preview link showed a doubled URL:
https://media.kiranbrahma.com/https://media.kiranbrahma.com/media-kiranbrahma/production/images/image-xxx.webp

The image itself renders fine on the deployed public site — this only breaks the admin-side preview.

Root cause

functions/admin/items/[itemId]/index.jsx builds the edit payload via serializeItemForFeed(row, {publicBucketUrl, ...}), which already absolutizes image fields with publicBucketUrl (FeedItemSerializer.js:58-59). AdminImageUploaderApp then calls urlJoinWithRelative(publicBucketUrl, currentImageUrl) again to build the preview link — re-prefixing a URL that's already absolute.

Fix

urlJoinWithRelative now returns an already-absolute (http:///https://) path unchanged, the same way it already short-circuits for a leading /. This is a shared utility with ~13 call sites (image previews, media library, RSS/JSON feed builders, SEO tags, brand logo) — the guard fixes the whole class of bug everywhere it could recur, not just this one screen.

Test plan

  • yarn test — 69/69 suites, 413/413 tests pass locally (added a regression test for urlJoinWithRelative covering the already-absolute case)

Editing an existing item (e.g. the home_page hero image) loads a payload
built by serializeItemForFeed(), which already absolutizes image fields
with publicBucketUrl. AdminImageUploaderApp then calls
urlJoinWithRelative(publicBucketUrl, currentImageUrl) again to build the
preview URL, prefixing an already-absolute URL a second time, e.g.
https://media.example.com/https://media.example.com/.../hero.webp.

urlJoinWithRelative now returns an already-absolute (http/https) path
unchanged instead of re-joining it, matching its existing early-return
for a leading "/". Fixes every call site, not just the image uploader.
@kiran-brahma
kiran-brahma merged commit ee3614d into main Jul 8, 2026
1 check passed
@kiran-brahma
kiran-brahma deleted the fix/double-prefixed-image-url branch July 8, 2026 05:36
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