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>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { FC, ImgHTMLAttributes } from 'react';
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
import Handlers from './components/Handlers';
|
|
|
|
interface Props {
|
|
show: Show;
|
|
onClick?: () => void;
|
|
className?: string;
|
|
lazy?: boolean;
|
|
priority?: boolean;
|
|
}
|
|
|
|
type FetchPriorityProps = ImgHTMLAttributes<HTMLImageElement> & { fetchpriority?: 'high' | 'low' | 'auto' };
|
|
|
|
const Poster: FC<Props> = ({ show, onClick, className, lazy = true, priority = false }) => {
|
|
const fetchPriorityProps: FetchPriorityProps = priority ? { fetchpriority: 'high' } : {};
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
'card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg',
|
|
'after:block after:absolute after:left-0 after:top-0 after:size-full after:bg-vignette after:pointer-events-none',
|
|
className
|
|
)}
|
|
>
|
|
<picture>
|
|
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
|
|
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
|
|
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
|
|
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
|
|
<img
|
|
className='size-full rounded-lg object-cover md:rounded-none md:rounded-l-lg'
|
|
loading={lazy ? 'lazy' : 'eager'}
|
|
src={show.poster['1x']}
|
|
alt={show.title}
|
|
{...fetchPriorityProps}
|
|
/>
|
|
</picture>
|
|
<Handlers show={show} onClick={onClick} />
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Poster;
|