Skip to content

Commit

Permalink
Merge pull request #22 from BKWLD/fix-using-sanity-cdn
Browse files Browse the repository at this point in the history
Fix using Sanity CDN for images
  • Loading branch information
weotch authored Aug 11, 2023
2 parents fc00b81 + 2fa1f7b commit c4f83b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/next/src/NextVisual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export default function NextVisual(

// An image rendered within the Visual
function NextImage({
src, sizes, alt, fit, position, priority, placeholderData
src, sizes, alt, fit, position, priority, loader, placeholderData
}: any): ReactElement {
return (
<Image
{ ...{ src, sizes, priority, alt } }
{ ...{ src, sizes, priority, loader, alt } }
fill
style={{
objectFit: fit,
Expand Down
5 changes: 0 additions & 5 deletions packages/sanity-next/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
module.exports = {
images: {

// Disable Next.js producing it's own crops within dev server which don't
// work with Cypress tests
// https://www.cypress.io/blog/2023/02/16/component-testing-next-js-with-cypress/
unoptimized: true,

// Support tests fetching imaages from placehold.co
remotePatterns: [
{
Expand Down
10 changes: 7 additions & 3 deletions packages/sanity-next/src/lib/urlBuilding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import createImageUrlBuilder from '@sanity/image-url'
import { getFileAsset, type SanityFileSource } from '@sanity/asset-utils'
import {
getFileAsset,
getImage,
type SanityFileSource
} from '@sanity/asset-utils'
import type { ImageUrlBuilder } from '@sanity/image-url/lib/types/builder'
import type { ImageLoader, ImageLoaderProps } from 'next/image'
import type { ImageLoaderProps } from 'next/image'
import type { SanityImageSource } from '@sanity/image-url/lib/types/types'
import { ObjectFit } from '@react-visual/next'

Expand Down Expand Up @@ -53,7 +57,7 @@ export function makeImageBuilder(source: SanityImageSource, {
export function imageLoader(
{ src, width, quality }: ImageLoaderProps
): string {
const builder = makeImageBuilder(src).width(width)
const builder = makeImageBuilder(getImage(src)).width(width)
if (quality) builder.quality(quality)
return builder.url()
}
Expand Down

0 comments on commit c4f83b3

Please sign in to comment.