-
-
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 all commits
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'; | ||||||||||||||||||||||||||||||||||
|
|
@@ -26,6 +27,7 @@ const Page: React.FC<Props> = ({ page, isIndividualPage = false }) => { | |||||||||||||||||||||||||||||||||
| year: 'numeric', | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
| const pageTitle = <p className={classNames(styles.title, styles.bold)}>{page.title}</p>; | ||||||||||||||||||||||||||||||||||
| const imageUrl = page.mainPhoto ? getImageUrl(page.mainPhoto) : ''; | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <div key={page.id} className={styles.pageContainer}> | ||||||||||||||||||||||||||||||||||
| <div className={styles.headerSection}> | ||||||||||||||||||||||||||||||||||
|
|
@@ -55,10 +57,16 @@ const Page: React.FC<Props> = ({ page, isIndividualPage = false }) => { | |||||||||||||||||||||||||||||||||
| {pageTitle} | ||||||||||||||||||||||||||||||||||
| </Link> | ||||||||||||||||||||||||||||||||||
| {page.summary} | ||||||||||||||||||||||||||||||||||
| {page.mainPhoto && ( | ||||||||||||||||||||||||||||||||||
| {page.mainPhoto && imageUrl && ( | ||||||||||||||||||||||||||||||||||
| <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={imageUrl} | ||||||||||||||||||||||||||||||||||
| alt="" | ||||||||||||||||||||||||||||||||||
| width={page.mainPhoto?.metadata?.dimensions?.width ?? 800} | ||||||||||||||||||||||||||||||||||
| height={page.mainPhoto?.metadata?.dimensions?.height ?? 600} | ||||||||||||||||||||||||||||||||||
| sizes="(max-width: 768px) 100vw, 800px" | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+69
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. Provide meaningful alt text for accessibility. The empty Apply this diff if <Image
className={styles.image}
src={imageUrl}
- alt=""
+ alt={page.mainPhoto.alt || page.title || 'Page hero image'}
width={page.mainPhoto?.metadata?.dimensions?.width ?? 800}
height={page.mainPhoto?.metadata?.dimensions?.height ?? 600}
sizes="(max-width: 768px) 100vw, 800px"
/>Based on learnings. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| </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.
Provide meaningful alt text for accessibility.
The empty
alt=""violates accessibility guidelines. Sanity assets may include descriptive metadata; ifasset.altor a similar field exists, use it. Otherwise, derive descriptive text from context (e.g., the surrounding content or page title).Apply this diff if
asset.altis available:<Image className={styles.image} src={imageUrl} - alt="" + alt={asset.alt || 'Inline image'} width={width} height={height} sizes="(max-width: 768px) 100vw, 800px" />Based on learnings.
🤖 Prompt for AI Agents