Fix double-prefixed image preview URL when editing an existing item - #30
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.webpThe image itself renders fine on the deployed public site — this only breaks the admin-side preview.
Root cause
functions/admin/items/[itemId]/index.jsxbuilds the edit payload viaserializeItemForFeed(row, {publicBucketUrl, ...}), which already absolutizes image fields withpublicBucketUrl(FeedItemSerializer.js:58-59).AdminImageUploaderAppthen callsurlJoinWithRelative(publicBucketUrl, currentImageUrl)again to build the preview link — re-prefixing a URL that's already absolute.Fix
urlJoinWithRelativenow 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 forurlJoinWithRelativecovering the already-absolute case)