Skip to content
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

Using Unpic with Vercel #757

Open
artt opened this issue Jan 13, 2025 · 0 comments
Open

Using Unpic with Vercel #757

artt opened this issue Jan 13, 2025 · 0 comments

Comments

@artt
Copy link

artt commented Jan 13, 2025

Describe the bug
When using Vercel adapter (to supposedly use Vercel's image service), there's a problem loading the image.

First version

Link to repo | Link to site

// @ts-check
import { defineConfig } from 'astro/config';
import { imageService } from "@unpic/astro/service";
import vercel from "@astrojs/vercel";

export default defineConfig({
  image: {
    service: imageService(),
  },
  adapter: vercel({
    imageService: true,
  }),
});

In this version, the image shows up correctly. The img element shows up as

<img src="/_vercel/image?url=_astro%2Ftest.BTqkgR0v.png&amp;w=640&amp;q=100" alt="Test" inputtedwidth="600" width="600" height="398" loading="lazy" decoding="async">

There's no srcset. Interestingly, when I change w=XXX to values other than 640, Vercel shows 404.

Second version

Link to repo | Link to site

// @ts-check
import { defineConfig } from 'astro/config';
import { imageService } from "@unpic/astro/service";
import vercel from "@astrojs/vercel";

export default defineConfig({
  image: {
    service: imageService(),
  },
  adapter: vercel({
    // imageService: true,
  }),
});

In this version, the image doesn't show up. The img element shows up with various source set. The url parameter is prepended with %2F.

<img src="/_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=600&amp;q=75" srcset="/_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=600&amp;q=75 600w, /_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=640&amp;q=75 640w, /_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=750&amp;q=75 750w, /_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=828&amp;q=75 828w, /_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=960&amp;q=75 960w, /_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=1080&amp;q=75 1080w, /_vercel/image?url=%2F_astro%2Ftest.BTqkgR0v.png&amp;w=1200&amp;q=75 1200w" alt="Test" url="/_astro/test.BTqkgR0v.png" loading="lazy" decoding="async" sizes="(min-width: 600px) 600px, 100vw" style="object-fit:cover;max-width:600px;max-height:398px;aspect-ratio:1.5075376884422111;width:100%">

Interestingly, when I change Removing the %2F and setting w=640 shows the image just fine.

Question

Am I doing something wrong? If I want just static website with Vercel's CDN, what do I have to do? With Netlify, I can just add the adapter and everything works. Link to that

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

No branches or pull requests

1 participant