-
-
Notifications
You must be signed in to change notification settings - Fork 530
Perf - Migrate legacy img tags to next/image and update styles/config to support remote assets #2561
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
base: testing
Are you sure you want to change the base?
Perf - Migrate legacy img tags to next/image and update styles/config to support remote assets #2561
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import React from 'react'; | ||
|
|
||
| import classNames from 'classnames'; | ||
| import Image from 'next/image'; | ||
| import useTranslation from 'next-translate/useTranslation'; | ||
|
|
||
| import PageBlocks from '../Blocks'; | ||
|
|
@@ -57,8 +58,14 @@ const Page: React.FC<Props> = ({ page, isIndividualPage = false }) => { | |
| {page.summary} | ||
| {page.mainPhoto && ( | ||
| <div className={styles.imageContainer}> | ||
| {/* eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text */} | ||
| <img className={styles.image} src={getImageUrl(page.mainPhoto)} /> | ||
| <Image | ||
| className={styles.image} | ||
| src={getImageUrl(page.mainPhoto)} | ||
| alt="" | ||
| width={page.mainPhoto?.metadata?.dimensions?.width ?? 800} | ||
| height={page.mainPhoto?.metadata?.dimensions?.height ?? 600} | ||
| sizes="(max-width: 768px) 100vw, 800px" | ||
|
Comment on lines
59
to
68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| /> | ||
| </div> | ||
| )} | ||
| </> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { DirectionProvider } from '@radix-ui/react-direction'; | |
| import { TooltipProvider } from '@radix-ui/react-tooltip'; | ||
| import Head from 'next/head'; | ||
| import { useRouter } from 'next/router'; | ||
| import Script from 'next/script'; | ||
|
|
||
| import AppContent from '@/components/AppContent/AppContent'; | ||
| import FontPreLoader from '@/components/Fonts/FontPreLoader'; | ||
|
|
@@ -32,6 +33,12 @@ function MyApp({ Component, pageProps }: { Component: any; pageProps: any }) { | |
| const { locale } = router; | ||
| const resolvedLocale = locale ?? 'en'; | ||
| const languageDirection = getDir(resolvedLocale); | ||
| const buildInfo = { | ||
| date: process.env.NEXT_PUBLIC_BUILD_DATE || new Date().toISOString(), | ||
| hash: process.env.NEXT_PUBLIC_COMMIT_HASH || 'development', | ||
| version: process.env.NEXT_PUBLIC_APP_VERSION || '', | ||
| env: process.env.NEXT_PUBLIC_APP_ENV, | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| document.documentElement.dir = languageDirection; | ||
|
|
@@ -50,18 +57,10 @@ function MyApp({ Component, pageProps }: { Component: any; pageProps: any }) { | |
| <link rel="apple-touch-icon" sizes="192x192" href="/images/logo/[email protected]" /> | ||
| <link rel="manifest" href="/manifest.json" /> | ||
| <link rel="preconnect" href={API_HOST} /> | ||
| <script | ||
| // eslint-disable-next-line react/no-danger | ||
| dangerouslySetInnerHTML={{ | ||
| __html: `window.__BUILD_INFO__ = { | ||
| date: "${process.env.NEXT_PUBLIC_BUILD_DATE || new Date().toISOString()}", | ||
| hash: "${process.env.NEXT_PUBLIC_COMMIT_HASH || 'development'}", | ||
| version: "${process.env.NEXT_PUBLIC_APP_VERSION || ''}", | ||
| env: "${process.env.NEXT_PUBLIC_APP_ENV}" | ||
| }`, | ||
| }} | ||
| /> | ||
| </Head> | ||
| <Script id="build-info" strategy="beforeInteractive"> | ||
| {`window.__BUILD_INFO__ = ${JSON.stringify(buildInfo)};`} | ||
| </Script> | ||
| <FontPreLoader locale={resolvedLocale} /> | ||
| <DirectionProvider dir={languageDirection}> | ||
| <TooltipProvider> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Image>when no URL is availableHere
getImageUrl(asset)is passed directly tonext/image. When Sanity is not configured,getImageUrlreturns''; unlike the previous<img>tag,next/imagewill throw because thesrcis empty. Any page containing inline images will fail to render in setups without Sanity credentials. A simple conditional render or fallback placeholder avoids the crash.Useful? React with 👍 / 👎.