Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Rot4tion
Copy link

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

… 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.
@Rot4tion Rot4tion changed the title fix(templates) Media component failing when set serverURL fix(templates): Media component failing when set serverURL Apr 25, 2025
@paulpopus paulpopus changed the title fix(templates): Media component failing when set serverURL templates: fix Media component failing when setting a custom serverURL Apr 28, 2025
@paulpopus
Copy link
Contributor

Thanks for your PR! Looks good to me, though could you copy these changes to the with-vercel-website template as well please?

There's a separate known issue with postgres in our CI, you might be able to get it to pass by merging latest main back into your branch otherwise wait until the next release for the fix to go out

Rot4tion and others added 2 commits April 29, 2025 08:13
Refactors media URL handling for Image and Video components
@Rot4tion
Copy link
Author

Thanks for your PR! Looks good to me, though could you copy these changes to the with-vercel-website template as well please?

There's a separate known issue with postgres in our CI, you might be able to get it to pass by merging latest main back into your branch otherwise wait until the next release for the fix to go out

done

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.

Website template's ImageMedia component fails if serverURL is set in Payload's config
2 participants