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
+73
View File
@@ -0,0 +1,73 @@
import { screen, waitFor, within } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
import { hydrateApp } from '@/test/hydrate';
// A direct load of a page with a search: the HTML was prerendered without it,
// so the first browser render must ignore it and the page applies it right
// after hydrating (BR-HYD-10 to 12). React reports a mismatch through
// onRecoverableError, which hydrate() collects.
beforeEach(() => {
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
Element.prototype.scrollTo = () => {};
});
afterEach(() => {
vi.unstubAllGlobals();
FakeIntersectionObserver.reset();
// @ts-expect-error -- jsdom has no Element.scrollTo of its own
delete Element.prototype.scrollTo;
});
describe('portfolio ?shoot= on a direct load', () => {
it('hydrates without a mismatch and then applies the filter', async () => {
const { errors } = await hydrateApp(
'/portfolio',
'/portfolio?shoot=gezin',
);
await waitFor(() =>
expect(
screen.getByRole('button', { name: 'Gezin', pressed: true }),
).toBeInTheDocument(),
);
expect(
within(screen.getByTestId('portfolio-grid')).getAllByRole('link'),
).toHaveLength(2);
expect(errors).toEqual([]);
});
it('hydrates a plain /portfolio with the whole list', async () => {
const { errors } = await hydrateApp('/portfolio', '/portfolio');
expect(
await screen.findByRole('button', { name: 'Alles', pressed: true }),
).toBeInTheDocument();
expect(errors).toEqual([]);
});
});
describe('contact ?pakket= on a direct load', () => {
it('hydrates without a mismatch and then preselects the package', async () => {
const { errors } = await hydrateApp(
'/contact',
'/contact?pakket=newborn',
);
expect(
await screen.findByTestId('contact-form-shoot', undefined, {
timeout: 10_000,
}),
).toHaveValue('newborn');
expect(errors).toEqual([]);
});
});
describe('homepage ?pakket= on a direct load', () => {
it('hydrates without a mismatch and then preselects the package', async () => {
const { errors } = await hydrateApp('/', '/?pakket=newborn');
expect(
await screen.findByTestId('contact-form-shoot', undefined, {
timeout: 10_000,
}),
).toHaveValue('newborn');
expect(errors).toEqual([]);
});
});