Makes the first render match the prerendered HTML

Search values, the 404 buttons and the footer year now apply after hydration.
The e-mail address stays out of the HTML behind a placeholder, and all review
texts are in the page, so crawlers can read them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 18:17:26 +01:00
co-authored by Claude Opus 5.5
parent 1574726c1d
commit 2c2e27e337
32 changed files with 1322 additions and 148 deletions
@@ -5,6 +5,7 @@ import homeContent from '@/content/homeContent';
import testimonials from '@/content/testimonials';
import { axeResults } from '@/test/axe';
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
import { serverHtml } from '@/test/hydrate';
import { renderWithProviders } from '@/test/renderWithProviders';
import { visibleTestimonials } from '@/lib/visibleTestimonials';
import Testimonials from './Testimonials';
@@ -201,3 +202,64 @@ describe('Testimonials', () => {
).toBeNull();
});
});
// Every review is in the prerendered HTML for search engines; the copies
// besides the longest one are hidden and inert (BR-LZY-02)
describe('Testimonials in the prerendered HTML', () => {
const shown = visibleTestimonials(testimonials);
const page = <Testimonials content={content} testimonials={testimonials} />;
it('holds the text of every visible review', async () => {
const doc = new DOMParser().parseFromString(
await serverHtml(page),
'text/html',
);
expect(shown.length).toBeGreaterThan(1);
for (const testimonial of shown) {
expect(
doc.querySelector(
`[data-testid="testimonial-${testimonial.id}"]`,
)?.textContent,
).toContain(testimonial.quote);
}
});
it('puts the longest in the flow and hides the others from readers', async () => {
const doc = new DOMParser().parseFromString(
await serverHtml(page),
'text/html',
);
const longest = shown.reduce((a, b) =>
b.quote.length > a.quote.length ? b : a,
);
for (const testimonial of shown) {
const copy = doc.querySelector(
`[data-testid="testimonial-${testimonial.id}"]`,
)!;
const hidden = copy.closest('[aria-hidden="true"][inert]');
if (testimonial === longest) {
expect(hidden).toBeNull();
} else {
expect(hidden).not.toBeNull();
}
}
});
it('exposes one review to readers while the carousel loads, without axe violations', async () => {
const { container } = await renderWithProviders(page);
const quotes = [...container.querySelectorAll('blockquote')];
expect(quotes).toHaveLength(shown.length);
expect(
quotes.filter((quote) => !quote.closest('[aria-hidden="true"]')),
).toHaveLength(1);
expect(await axeResults(container)).toHaveNoViolations();
});
it('does not add copies for a single review', async () => {
const html = await serverHtml(
<Testimonials content={content} testimonials={[shown[0]]} />,
);
expect(html.match(/data-testid="testimonial-/g)).toHaveLength(1);
expect(html).not.toContain('inert');
});
});
@@ -1,5 +1,5 @@
import { lazy, Suspense } from 'react';
import { Box } from '@chakra-ui/react';
import { Box, VisuallyHidden } from '@chakra-ui/react';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
@@ -71,7 +71,10 @@ export default function Testimonials({
// 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.
// #contact that passes this section while it loads. The other reviews are in
// the page too, visually hidden, so the prerendered HTML holds every review
// text for search engines (BR-LZY-02). They are aria-hidden and inert, so
// assistive technology reads each review once, in the carousel.
function CarouselPlaceholder({
testimonials,
}: {
@@ -85,6 +88,15 @@ function CarouselPlaceholder({
<Box ps={{ base: 0, sm: '1.5rem' }} pb={{ base: 0, sm: '1.5rem' }}>
<TestimonialSlide testimonial={longest} />
</Box>
{testimonials
.filter((testimonial) => testimonial !== longest)
.map((testimonial) => (
<VisuallyHidden key={testimonial.id} asChild>
<Box aria-hidden="true" inert>
<TestimonialSlide testimonial={testimonial} />
</Box>
</VisuallyHidden>
))}
{/* The control bar: 48px buttons below the same margin */}
<Box mt="clamp(2.5rem, 5vw, 4rem)" h="48px" />
</Box>