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');
});
});