next-image-export-optimizer icon indicating copy to clipboard operation
next-image-export-optimizer copied to clipboard

`src` does not reflect `basePath` for statically-imported images

Open srmagura opened this issue 2 years ago • 0 comments

Next allows you to configure a basePath so you can serve your site from a subpath. For example, we deploy our Next.js site to www.spotvirtual.com/_preview so we can test changes before making them live at www.spotvirtual.com.

I noticed that the generateImageURL code from ExportedImage.tsx does not take basePath into account for statically-imported images. Ideally, it would prepend the basePath since this is what next/image does.

It should be easy to fix. I may send a PR for this, though I am leaning towards changing our deployment so that the preview site is served from a different subdomain, e.g. www-preview.spotvirtual.com. This would prevent issues like this from arising in the first place.

There is a related next.config.js property called assetPrefix. Ideally the PR for this would take assetPrefix into account too. If both basePath and assetPrefix are set, I'm not sure which one "wins".

srmagura avatar Oct 07 '22 14:10 srmagura