Skip to content

Commit 644bcd3

Browse files
committed
Fix bug with absolute image url by removing the hostname
1 parent b039c5c commit 644bcd3

File tree

13 files changed

+76
-146
lines changed

13 files changed

+76
-146
lines changed

src/app/(frontend)/[locale]/conclusion/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import symbol from '@public/images/symbol.svg'
55
import whiteLogo from '@public/images/logoWhite.svg'
66
import { RichText } from '@payloadcms/richtext-lexical/react'
77
import { Link } from '@/i18n/navigation'
8-
import Image from 'next/image'
8+
import Image from '@/components/global/Image'
99
import { draftMode } from 'next/headers'
1010

1111
export const dynamic = 'error'
@@ -57,7 +57,7 @@ export default async function Page({ params }: { params: Promise<{ locale: 'en'
5757
<Image
5858
src={whiteLogo}
5959
alt="Vector: Interior Design"
60-
className="h-10 self-start md:self-center w-fit"
60+
className="h-10 self-center bg-vector-grey w-fit"
6161
/>
6262
<div className="bg-vector-orange -bottom-15 absolute right-0 h-2 w-8"></div>
6363
</div>

src/app/(frontend)/[locale]/page.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import { Link } from '@/i18n/navigation'
1717

1818
import '@styles/descriptions.scss'
1919
import '@styles/nav.scss'
20-
import ImageSkeleton from '@/components/global/ImageSkeleton'
20+
import Image from '@/components/global/Image'
2121
import designer from '@public/images/tony.jpg'
22-
import Image from 'next/image'
2322

2423
type MainPageImageType = NonNullable<MainPageImage['images']>[number]
2524

@@ -78,9 +77,15 @@ function imageBlock(
7877
style={{ height: `${image.deskConfig.imgSize}svh` }}
7978
className="max-w-3/5 xl:max-w-11/20 2xl:max-w-full"
8079
>
81-
<ImageSkeleton
82-
image={image.image as Media}
83-
sizes={`(min-width: 1280px) 55vw, (min-width: 1440px) 70vw, 60vw`}
80+
<Image
81+
src={imageFile.url!}
82+
alt={imageFile.alt}
83+
className="h-full w-auto object-contain"
84+
width={imageFile.width!}
85+
height={imageFile.height!}
86+
placeholder="blur"
87+
blurDataURL={imageFile.sizes!.loading!.url!}
88+
sizes="(min-width: 1280px) 55vw, (min-width: 1440px) 70vw, 60vw"
8489
/>
8590
</div>
8691
{image.description && descriptionPositionDesktop && (
@@ -102,9 +107,14 @@ function imageBlock(
102107
flexDirection: flexDirectionMobile,
103108
}}
104109
>
105-
<ImageSkeleton
106-
image={imageFile}
107-
className="shrink"
110+
<Image
111+
src={imageFile.url!}
112+
alt={imageFile.alt}
113+
className="h-full w-auto object-contain shrink"
114+
width={imageFile.width!}
115+
height={imageFile.height!}
116+
placeholder="blur"
117+
blurDataURL={imageFile.sizes!.loading!.url!}
108118
sizes={overflowMobile ? '100vw' : '90vw'}
109119
/>
110120
{image.description && descPosMobile && (
@@ -160,7 +170,16 @@ function navBlock(
160170
style={{ height: `${image.imgSize}%` }}
161171
className="relative max-xl:h-fit! max-xl:w-full lg:max-w-1/2 max-xl:max-w-none [&_img]:w-full!"
162172
>
163-
<ImageSkeleton image={image.image as Media} sizes={`(max-width: 1024px) 100vw, 50vw`} />
173+
<Image
174+
src={imageFile.url!}
175+
alt={imageFile.alt}
176+
className="h-full w-auto object-contain"
177+
width={imageFile.width!}
178+
height={imageFile.height!}
179+
placeholder="blur"
180+
blurDataURL={imageFile.sizes!.loading!.url!}
181+
sizes={`(max-width: 1024px) 100vw, 50vw`}
182+
/>
164183
</div>
165184

166185
<ul className="flex items-center justify-center gap-5 p-5 text-xl lg:h-4/5">

src/app/(frontend)/[locale]/projects/[id]/page.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import RefreshRouteOnSave from '@/components/admin/RefreshRouteOnSave'
88
import headersConverter from '@/lib/utils/converter'
99

1010
import { ReactNode } from 'react'
11-
import ImageSkeleton from '@/components/global/ImageSkeleton'
1211

1312
import '@styles/arrow.css'
1413
import '@styles/descriptions.scss'
1514
import { Link } from '@/i18n/navigation'
1615
import { draftMode } from 'next/headers'
1716
import { Metadata } from 'next'
1817
import { convertLexicalToPlaintext } from '@payloadcms/richtext-lexical/plaintext'
19-
import Image from 'next/image'
20-
18+
import Image from '@/components/global/Image'
2119
interface Props {
2220
params: Promise<{
2321
locale: 'en' | 'es'
@@ -45,8 +43,12 @@ function DesktopImage(img: ProjectImage): ReactNode {
4543
style={{ flexDirection }}
4644
>
4745
{imageFile?.url ? (
48-
<ImageSkeleton
49-
image={imageFile}
46+
<Image
47+
src={imageFile.url!}
48+
alt={imageFile.alt}
49+
width={imageFile.width!}
50+
height={imageFile.height!}
51+
className="h-full w-auto object-contain"
5052
sizes={imageFile.width! <= imageFile.height! ? '40vw' : '70vw'}
5153
style={{ height: `${img.deskConf.imageSize}svh` }}
5254
/>
@@ -209,10 +211,13 @@ const Page = async ({ params }: Props) => {
209211
style={{ backgroundColor: image.bgColor }}
210212
key={`${img.id}-mobile`}
211213
>
212-
<ImageSkeleton
213-
image={imageFile}
214-
sizes={`(min-width: 1280px) 60vw, 75vw`}
215-
className="max-w-3/4 mx-auto xl:max-w-full md:h-80 md:w-auto"
214+
<Image
215+
src={imageFile.url!}
216+
alt={imageFile.alt}
217+
width={imageFile.width!}
218+
height={imageFile.height!}
219+
className="max-w-3/4 mx-auto xl:max-w-full md:h-80 md:w-auto h-full w-auto object-contain"
220+
sizes="(min-width: 1280px) 60vw, 75vw"
216221
/>
217222

218223
<div className="px-8">

src/app/(frontend)/[locale]/sculptures/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getPayload } from 'payload'
22
import config from '@payload-config'
33
import { Media, Sculpture } from '@/payload-types'
4-
import Image from 'next/image'
4+
import Image from '@/components/global/Image'
55
import { RichText } from '@payloadcms/richtext-lexical/react'
66
import ScrollToTop from '@/components/sculptures/ScrollToTop'
77
import { draftMode } from 'next/headers'

src/components/carousel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '@styles/glide.css'
44
import Glide, { Controls, Swipe, Breakpoints } from '@glidejs/glide/dist/glide.modular.esm'
55
import '@glidejs/glide/dist/css/glide.core.min.css'
66
import { Media } from '@/payload-types'
7-
import Image from 'next/image'
7+
import Image from '@/components/global/Image'
88
import { useEffect } from 'react'
99
import { Link } from '@/i18n/navigation'
1010
import { useLocale } from 'next-intl'

src/components/global/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import Image from 'next/image'
3+
import Image from '@/components/global/Image'
44
import logo from '@public/images/logo.svg'
55
import LanguageSelect from './LanguageSelect'
66
import { useState, useEffect, useRef } from 'react'

src/components/global/Image.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import ReactImage from 'next/image'
2+
import '@styles/skeleton.scss'
3+
4+
type ImageProps = React.ComponentPropsWithoutRef<typeof ReactImage>
5+
6+
/**
7+
* This wrapper around Next's `Image` component that
8+
* removes the website's hostname (Indicated by `process.env.NEXT_PUBLIC_PAYLOAD_URL`)
9+
* from an image URL so that it becomes relative to avoid issues with remotePatterns and docker containers.
10+
* It accepts all the props `Image` accepts and does src.replace(process.env.NEXT_PUBLIC_PAYLOAD_URL || '', '')
11+
* to remove the hostname.
12+
*/
13+
export default function Image({ ...props }: ImageProps) {
14+
return (
15+
<ReactImage
16+
{...props}
17+
src={
18+
typeof props.src === 'string'
19+
? props.src.replace(process.env.NEXT_PUBLIC_PAYLOAD_URL || '', '')
20+
: props.src
21+
}
22+
blurDataURL={props.blurDataURL?.replace(process.env.NEXT_PUBLIC_PAYLOAD_URL || '', '')}
23+
/>
24+
)
25+
}

src/components/global/ImageSkeleton.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/mainPage/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import Image from 'next/image'
3+
import Image from '@/components/global/Image'
44
import logoWhite from '@public/images/logoWhite.svg'
55
import { useTranslations } from 'next-intl'
66

src/components/mainPage/NavLine.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import '@styles/nav.scss'
44

5-
import Image from 'next/image'
5+
import Image from '@/components/global/Image'
66
import symbol from '@public/images/symbol.svg'
77
import { useEffect } from 'react'
88

0 commit comments

Comments
 (0)