perf: mark hero poster image as high fetch priority
Lighthouse flagged the LCP carousel poster for missing fetchpriority=high. Adds a priority prop to Poster that emits the lowercase fetchpriority attribute (untyped in this @types/react version, so React forwards it through as a custom attribute) only on the eagerly-rendered hero image. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
127a02f4e1
commit
07bbb576f6
2 files changed
+35
-25
No files matched your search
@@ -40,7 +40,9 @@ const Carousel = memo(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='card-aspect-ratio static-aspect-ratio relative mx-auto'>
|
<div className='card-aspect-ratio static-aspect-ratio relative mx-auto'>
|
||||||
{!loaded && <Poster lazy={false} show={shows![index]} className='pointer-events-none absolute left-0 top-0' />}
|
{!loaded && (
|
||||||
|
<Poster lazy={false} priority show={shows![index]} className='pointer-events-none absolute left-0 top-0' />
|
||||||
|
)}
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
initialItemCount={1}
|
initialItemCount={1}
|
||||||
horizontalDirection
|
horizontalDirection
|
||||||
|
|||||||
+32
-24
@@ -1,4 +1,4 @@
|
|||||||
import { FC } from 'react';
|
import { FC, ImgHTMLAttributes } from 'react';
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -9,30 +9,38 @@ interface Props {
|
|||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
lazy?: boolean;
|
lazy?: boolean;
|
||||||
|
priority?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poster: FC<Props> = ({ show, onClick, className, lazy = true }) => (
|
type FetchPriorityProps = ImgHTMLAttributes<HTMLImageElement> & { fetchpriority?: 'high' | 'low' | 'auto' };
|
||||||
<div
|
|
||||||
className={cn(
|
const Poster: FC<Props> = ({ show, onClick, className, lazy = true, priority = false }) => {
|
||||||
'card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg',
|
const fetchPriorityProps: FetchPriorityProps = priority ? { fetchpriority: 'high' } : {};
|
||||||
'after:block after:absolute after:left-0 after:top-0 after:size-full after:bg-vignette after:pointer-events-none',
|
|
||||||
className
|
return (
|
||||||
)}
|
<div
|
||||||
>
|
className={cn(
|
||||||
<picture>
|
'card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg',
|
||||||
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
|
'after:block after:absolute after:left-0 after:top-0 after:size-full after:bg-vignette after:pointer-events-none',
|
||||||
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
|
className
|
||||||
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
|
)}
|
||||||
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
|
>
|
||||||
<img
|
<picture>
|
||||||
className='size-full rounded-lg object-cover md:rounded-none md:rounded-l-lg'
|
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
|
||||||
loading={lazy ? 'lazy' : 'eager'}
|
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
|
||||||
src={show.poster['1x']}
|
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
|
||||||
alt={show.title}
|
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
|
||||||
/>
|
<img
|
||||||
</picture>
|
className='size-full rounded-lg object-cover md:rounded-none md:rounded-l-lg'
|
||||||
<Handlers show={show} onClick={onClick} />
|
loading={lazy ? 'lazy' : 'eager'}
|
||||||
</div>
|
src={show.poster['1x']}
|
||||||
);
|
alt={show.title}
|
||||||
|
{...fetchPriorityProps}
|
||||||
|
/>
|
||||||
|
</picture>
|
||||||
|
<Handlers show={show} onClick={onClick} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default Poster;
|
export default Poster;
|
||||||
Reference in new issue
Block a user