Skip to content

Shopify Provider - Broken sources when preexisting URL params #2047

@francislg2

Description

@francislg2

This line:

url: withBase(joinURL(src + (operations ? ('?' + operations) : '')), baseURL),

Does not check if there already are URL params on the source before appending the new ones.


Shopify often has an asset version in the URL,

ex: ...jpg?v=1763534395

which was causing issues with double "?"

ex: ?v=1763534395?width=200


I have made a custom provider as a workaround, but it would be best to fix the original lib file.

export default defineProvider<ShopifyOptions>({
  getImage: (src, { modifiers, baseURL = "" }) => {
    const operations = operationsGenerator(modifiers);

    const [baseUrl, existingQuery] = src.split("?", 2);
    const mergedParams = new URLSearchParams(existingQuery || "");

    if (operations) {
      const operationsParams = new URLSearchParams(operations);
      for (const [key, value] of operationsParams) {
        mergedParams.set(key, value);
      }
    }

    const queryString = mergedParams.toString();

    return {
      url: withBase(
        joinURL(baseUrl + (queryString ? "?" + queryString : "")),
        baseURL
      ),
    };
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions