A Next.js application that aggregates and displays content from Instagram, TikTok, and YouTube in a unified grid layout with consistent sizing and popup video players.
First, run the development server:
pnpm devOpen http://localhost:3000 with your browser to see the result.
- Problem: Instagram embeds were expanding vertically and breaking grid layout
- Solution: Implemented 9:16 aspect ratio (
paddingTop: "177.78%") for all thumbnails - Result: All embeds (Instagram, TikTok, YouTube) now have uniform sizing
- Problem: First TikTok video worked, but subsequent ones failed to load
- Root Cause: TikTok's embed script conflicts with multiple instances
- Solution: Switched from problematic embed script to direct iframe with official embed URLs
- Implementation:
https://www.tiktok.com/embed/${videoId}instead oftiktok-embed.js
- Problem: Randomization caused server/client HTML mismatch
- Solution: Implemented seeded randomization for consistent order between server and client
- Implementation: Fisher-Yates shuffle with fixed seed (42)
- Feature: Videos display in random order on each page load
- Implementation: Seeded shuffle algorithm for consistent randomization
- Result: Fresh layout experience every time
InlineInstagramEmbed: Direct iframe approach for grid displayThirdPartyEmbed: Modal popup player for all platformsloadScriptOnce: Prevents duplicate script loading
- Grid Layout: CSS Grid with responsive columns (
minmax(220px, 1fr)) - Aspect Ratios: 9:16 for thumbnails, 9:16 for modal videos
- Dark Theme: Consistent color scheme throughout
type Clip = {
id: string;
provider: "youtube" | "tiktok" | "instagram";
folder: string;
title?: string;
youtube?: { videoId: string };
tiktok?: { videoId: string; citeUrl?: string };
instagram?: { permalink: string };
thumbUrl?: string;
};- Aspect Ratio Approach: Use
paddingTop: "177.78%"for 9:16 ratio containers - TikTok Embeds: Use
https://www.tiktok.com/embed/${videoId}URLs - Instagram Embeds: Use direct iframe with
/embedURLs - YouTube Embeds: Standard embed URLs work reliably
- 9:16 Aspect Ratio: Instagram Reel/YouTube Short format, mobile-optimized
- Direct Iframe URLs: Bypass platform embed script conflicts
- Seeded Randomization: Prevents hydration issues in React Native
- Consistent Sizing: All platforms maintain uniform dimensions
- Touch Interactions: Ensure clickable areas are properly sized
- Performance: Direct iframes are more performant than complex embed scripts
- Cross-Platform: These solutions work in both web and React Native environments
- Instagram Posts: 10 cooking-related posts
- TikTok Videos: 8 cooking videos from various creators
- YouTube Videos: 10 cooking channels and shorts
- All content categorized under "Cooking" folder
- Random display order for variety
- Consistent 9:16 aspect ratio across all platforms
// Seeded randomization for consistent ordering
const clips = useMemo(() => {
const shuffled = [...initialClips];
let seed = 42; // Fixed seed for consistent randomization
for (let i = shuffled.length - 1; i > 0; i--) {
seed = (seed * 9301 + 49297) % 233280; // Simple PRNG
const j = seed % (i + 1);
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}, []);
// Direct TikTok iframe (no script conflicts)
if (clip.provider === "tiktok" && clip.tiktok) {
const iframe = document.createElement("iframe");
iframe.src = `https://www.tiktok.com/embed/${videoId}`;
// ... iframe setup
}thumbWrap: {
position: "relative",
background: "#000",
paddingTop: "177.78%", // 9:16 aspect ratio
}
modalVideoWrap: {
position: "relative",
paddingTop: "177.78%", // 9:16 aspect ratio for modal
background: "#000",
}- Symptom: Instagram embeds taller than other thumbnails
- Solution: Use 9:16 aspect ratio containers with
overflow: hidden
- Symptom: Second+ TikTok videos fail to load
- Solution: Use direct iframe with
/embedURLs, avoid embed scripts
- Symptom: Server/client HTML mismatch
- Solution: Seeded randomization instead of
Math.random()
- Symptom: "Firefox Can't Open This Page" for TikTok
- Solution: Use official embed URLs (
/embed/not/video/)
- Next.js 14: App Router, React 18
- React Hooks: useState, useEffect, useMemo, useRef
- CSS-in-JS: Inline styles for consistency
- No External UI Libraries: Pure React implementation
- โ Consistent Sizing: All embeds maintain 9:16 aspect ratio
- โ Reliable Loading: Multiple TikTok videos work without conflicts
- โ No Hydration Errors: Seeded randomization prevents mismatches
- โ Cross-Platform Ready: Solutions work in web and React Native
- โ Performance: Direct iframes outperform complex embed scripts
- Lazy Loading: Implement intersection observer for performance
- Error Boundaries: Better error handling for failed embeds
- Analytics: Track embed loading success rates
- Mobile Optimization: Touch gestures and mobile-specific interactions
Note: This implementation specifically addresses the challenges of embedding social media content with consistent sizing and reliable loading across multiple platforms. The solutions are designed to work in both web and React Native (Expo Go) environments.