Inconsistent image import behavior with adapter-vercel
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
When I import an unoptimized image in a SvelteKit page, say on the /image route, like this
import src from './mike-van-den-bos-fbQv3cx--bM-unsplash.jpg';
using adapter-vercel, I get inconsistent values for src:
-
When I go to
/imagedirectly (or do a hard reload),srcresolves to a root-relative path, e.g./_app/immutable/assets/mike-van-den-bos-fbQv3cx--bM-unsplash.a5Y7YFW3.jpg. -
When I navigate from
/to/imageby clicking a link,srcresolves to a fully qualified URL that includes the Vercel deployment URL, e.g.https://repro-sveltekit-vercel-image-optimization.vercel.app/_app/immutable/assets/mike-van-den-bos-fbQv3cx--bM-unsplash.a5Y7YFW3.jpg.
This behavior interferes with the Vercel Image Optimization API because a srcset URL like this (note the fully qualified URL in url)
/_vercel/image?url=https%3A%2F%2Frepro-sveltekit-vercel-image-optimization.vercel.app%2F_app%2Fimmutable%2Fassets%2Fmike-van-den-bos-fbQv3cx--bM-unsplash.a5Y7YFW3.jpg&w=1200&q=85
results in status 400 while a URL like this (note the root-relative URL in url)
/_vercel/image?url=%2F_app%2Fimmutable%2Fassets%2Fmike-van-den-bos-fbQv3cx--bM-unsplash.a5Y7YFW3.jpg&w=1200&q=85
results in a successful image generation.
In other words, the inconsistent src breaks the Vercel Image Optimization API whenever it is a fully qualified URL. The Vercel Image API documentation does not provide any details on why it would not work when an image using the fully qualified deployment URL is passed in. It might be to prevent recursive API invocations. But not sure.
But that aside, the question is whether src in above import not resolving consistenly is a bug. I also compared with the adapter-node behavior. For adapter-node src would always be a root-relative path.
Reproduction
Minimal repro repo: https://github.com/maiertech/repro-sveltekit-vercel-image-optimization.
The repro cannot be observed when running pnpm dev. You have to look at the Vercel production deployment.
- Go to https://repro-sveltekit-vercel-image-optimization.vercel.app/.
- Click "responsive image page".
- You should see a broken image.
- Check out the
imgtag in the DevTools. Note thatsrcand theurlparams insrcsetuse the fully qaulified URL inlcuding the deployment URL origin. - Now do a hard reload of the page.
- You should see the image.
- Note in the DevTools that the
imgtag now uses root-relative URLs (which are server-side rendered).
Logs
System Info
System:
OS: macOS 15.6
CPU: (8) arm64 Apple M3
Memory: 609.17 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.18.0 - /opt/homebrew/opt/node@22/bin/node
npm: 10.9.3 - /opt/homebrew/opt/node@22/bin/npm
pnpm: 10.14.0 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 138.0.7204.184
Safari: 18.6
npmPackages:
@sveltejs/adapter-vercel: ^5.8.1 => 5.8.1
@sveltejs/kit: ^2.22.0 => 2.27.0
@sveltejs/vite-plugin-svelte: ^6.0.0 => 6.1.0
svelte: ^5.0.0 => 5.37.2
vite: ^7.0.4 => 7.0.6
Severity
serious, but I can work around it
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked minimal repro and the /image route, comparing adapter-vercel behavior in a Vercel production deployment with adapter-node and with pnpm dev. Reproduce both hard reload and client navigation, then make imported image URLs consistent and verify that the Vercel image optimization request succeeds in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100