import { lazy, Suspense } from 'react'; import { Box } from '@chakra-ui/react'; import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage'; import PageSection from '@/components/PageSection/PageSection'; import Reveal from '@/components/Reveal/Reveal'; import SectionHeading from '@/components/SectionHeading/SectionHeading'; import type { HomeContent, Testimonial } from '@/content/types'; import useInView from '@/hooks/useInView'; import { visibleTestimonials } from '@/lib/visibleTestimonials'; import TestimonialSlide from './TestimonialSlide'; // The carousel (Chakra/Zag) is the heaviest code on the page and sits far // below the hero. It is loaded only when this section comes near the screen, // so the hero (the largest contentful paint) never waits for it: loading it // with the page cost ±0.02 Lighthouse performance on mobile. const TestimonialCarousel = lazy(() => import('./TestimonialCarousel')); const TITLE_ID = 'testimonials-title'; type TestimonialsProps = { content: HomeContent['testimonials']; testimonials: Testimonial[]; }; // "Lieve woorden": client reviews, one at a time (design .testimonials). // Without a valid review the section is left out; a single review is shown // without carousel controls. The heading is always rendered. export default function Testimonials({ content, testimonials, }: TestimonialsProps) { const shown = visibleTestimonials(testimonials); const { ref, inView } = useInView({ rootMargin: DEFERRED_LOAD_MARGIN, }); if (shown.length === 0) return null; return ( {shown.length === 1 ? ( ) : ( {inView ? ( } > ) : ( )} )} ); } // Stands in for the carousel until it has loaded: the longest review laid // out exactly like a slide (same padding), plus the controls' height. That // makes it as tall as the carousel at every screen width, so nothing below // moves when the carousel takes its place, not even during a scroll to // #contact that passes this section while it loads. function CarouselPlaceholder({ testimonials, }: { testimonials: Testimonial[]; }) { const longest = testimonials.reduce((a, b) => b.quote.length > a.quote.length ? b : a, ); return ( {/* The control bar: 48px buttons below the same margin */} ); }