Skip to content

Why Popular Video Cards Have No Thumbnails

Adityo Guni Waluyo

Popular marquee cards checked explicit thumbnails, leaving video items on gradients. Fix: explicit thumbnail → i.ytimg hqdefault → gradient. hqdefault always exists for public videos.

TL;DR

Video items showed a gradient placeholder. A fallback chain was added to display thumbnails. It uses YouTube's image CDN for video thumbnails.

The Problem: Video Items Show Only a Gradient Placeholder

I opened the KotaPortal "Popular Articles" marquee and video items looked broken: just a blue-purple gradient placeholder, no thumbnail. Digging into the code: PopularMarquee only checked for an explicit thumbnail field. Video entities from YouTube don't have that — they have video_youtube_id.

The Fix: A Fallback Chain in the Component

Commit 65ed6ab adds a fallback chain in the component: explicit thumbnail if present, construct i.ytimg.com/vi/{videoId}/hqdefault.jpg, then gradient placeholder. hqdefault (480x360) always exists for public videos [7][8]. maxresdefault (1280x720) only exists for HD videos — don't use it without a fallback.

Configuration & Implementation

Next.js next/image needs remotePatterns for external domains [9]. CSP img-src already allows i.ytimg.com + img.youtube.com. No YouTube Data API quota needed — pure image CDN fetches.

const getPoster = (item: PopulerItem) => {
  if (item.thumbnail) return item.thumbnail
  if (item.video_type === 'youtube' && item.video_youtube_id) {
    return `https://i.ytimg.com/vi/${item.video_youtube_id}/hqdefault.jpg`
  }
  return '/gradient-placeholder.svg'
}

PopulerItem type + 3 pillar mappings (olahraga/kebudayaan/kepemudaan) now carry video_type + video_youtube_id. Read-path only, no user input.

Sources

  1. ThumbnailsGrabber: maxresdefault not always present; hqdefault always exists
  2. open-navigator/youtubeThumbnail.ts: hqdefault guaranteed; maxresdefault needs fallback
  3. Next.js Image: remotePatterns for i.ytimg.com / img.youtube.com

Related articles