-
Notifications
You must be signed in to change notification settings - Fork 2.5k
templates: fix Media component failing when setting a custom serverURL #12214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
templates: fix Media component failing when setting a custom serverURL #12214
Conversation
… if serverURL is set in Payload's config Replaces URL construction with dedicated media URL function Implements a new utility function for constructing media URLs, enhancing code maintainability and clarity. Updates the ImageMedia and VideoMedia components to utilize the new function for generating source URLs, improving consistency in URL handling.
Thanks for your PR! Looks good to me, though could you copy these changes to the There's a separate known issue with postgres in our CI, you might be able to get it to pass by merging latest |
…deoMedia-fails-when-set-serverURL-config
Refactors media URL handling for Image and Video components
done |
…ils-when-set-serverURL-config
…ils-when-set-serverURL-config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this PR!
#12214) ### What? Fixes #12171 ### Why? Previously, the ImageMedia component was not properly handling URL formatting when a serverURL was configured in Payload. This caused images to fail to load when using a custom serverURL. By extracting the URL handling logic into a separate utility function, we ensure consistent URL processing across both image and video components. ### How? 1. Created a new utility function getMediaUrl in `src/utilities/getMediaUrl.ts` that: - Properly checks for HTTP/HTTPS protocols - Handles null or undefined URL values - Supports cache tags to prevent caching issues - Uses `getClientSideURL()` for relative paths 2. Updated the ImageMedia component to use this utility function instead of inline URL processing logic 3. Updated the VideoMedia component to also use the same utility function for consistency
🚀 This is included in version v3.38.0 |
#12214) ### What? Fixes #12171 ### Why? Previously, the ImageMedia component was not properly handling URL formatting when a serverURL was configured in Payload. This caused images to fail to load when using a custom serverURL. By extracting the URL handling logic into a separate utility function, we ensure consistent URL processing across both image and video components. ### How? 1. Created a new utility function getMediaUrl in `src/utilities/getMediaUrl.ts` that: - Properly checks for HTTP/HTTPS protocols - Handles null or undefined URL values - Supports cache tags to prevent caching issues - Uses `getClientSideURL()` for relative paths 2. Updated the ImageMedia component to use this utility function instead of inline URL processing logic 3. Updated the VideoMedia component to also use the same utility function for consistency
What?
Fixes #12171
Why?
Previously, the ImageMedia component was not properly handling URL formatting when a serverURL was configured in Payload. This caused images to fail to load when using a custom serverURL. By extracting the URL handling logic into a separate utility function, we ensure consistent URL processing across both image and video components.
How?
src/utilities/getMediaUrl.ts
that:getClientSideURL()
for relative paths