Client: no 'use client' on barrels, lazy lightbox viewer, rAF table of contents, Turnstile polling stops, reduced motion, Media eager, 404 placeholder option

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 13:51:39 +01:00
co-authored by Claude Opus 5.5
parent 1d6108765c
commit 21073d98d0
17 changed files with 72 additions and 38 deletions
+7 -2
View File
@@ -42,6 +42,11 @@ export const MEDIA_SIZES = {
export type MediaImageOptions = {
/** Alt override (decorative images: ''). Default: the document's alt. */
alt?: string
/**
* Above the fold but not the LCP image (a header logo): loads at once (`loading="eager"`) WITHOUT
* fetchPriority="high" or a preload, so it does not compete with the one `priority` image. Ignored with `priority`.
*/
eager?: boolean
/**
* Dominant colour as the <img> background while it loads. The style stays after
* load, so it would show through transparent pixels (white logo on a black box).
@@ -88,7 +93,7 @@ const asDoc = (resource: unknown): MediaDoc | null =>
*/
export function mediaImageProps(
resource: unknown,
{ alt, placeholderColor = 'auto', priority = false, sizes = '100vw' }: MediaImageOptions = {},
{ alt, eager = false, placeholderColor = 'auto', priority = false, sizes = '100vw' }: MediaImageOptions = {},
): MediaImageProps | null {
const doc = asDoc(resource)
if (!doc || doc.mimeType?.startsWith('video/')) {return null}
@@ -109,7 +114,7 @@ export function mediaImageProps(
width: doc.width,
...(priority
? { fetchPriority: 'high' as const, loading: 'eager' as const, preload: true }
: { loading: 'lazy' as const }),
: { loading: eager ? ('eager' as const) : ('lazy' as const) }),
...(blur ? { blurDataURL: blur, placeholder: 'blur' as const } : {}),
...(Object.keys(style).length ? { style } : {}),
}