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 -1
View File
@@ -11,6 +11,7 @@ import contactContent from '../content/contactContent';
import packages from '../content/packages';
import siteContent from '../content/siteContent';
import { withReplyTime } from '../lib/withReplyTime';
import useHydrated from '../hooks/useHydrated';
import { contactPage, pageHead, structuredDataScript } from '../seo';
// ?pakket= from a link elsewhere on the site. Only text is kept; the panel
@@ -34,7 +35,10 @@ export const Route = createFileRoute('/contact')({
// form (BR-CP-01..04). The card is in the page twice, one per layout, so the
// reading order always matches what is shown.
function Contact() {
const { pakket } = Route.useSearch();
const { pakket: searched } = Route.useSearch();
// The search only counts after hydration, so the prerendered HTML and the
// first browser render agree (BR-HYD-10)
const pakket = useHydrated() ? searched : undefined;
const navigate = useNavigate();
const { head, formTitle, detailsTitle, image, portrait } = contactContent;
const { email, socials, contactForm } = siteContent;
+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([]);
});
});
+5 -1
View File
@@ -13,6 +13,7 @@ import packages from '../content/packages';
import testimonials from '../content/testimonials';
import siteContent from '../content/siteContent';
import { visibleSocials } from '../lib/visibleSocials';
import useHydrated from '../hooks/useHydrated';
import { pageHead } from '../seo';
// ?pakket= from a "Boek" link on a price card. Only text is kept; whether it
@@ -28,7 +29,10 @@ export const Route = createFileRoute('/')({
// The homepage: the hero, then the sections in the order of LAYOUT.md
function Index() {
const { pakket } = Route.useSearch();
const { pakket: searched } = Route.useSearch();
// The search only counts after hydration, so the prerendered HTML and the
// first browser render agree (BR-HYD-10)
const pakket = useHydrated() ? searched : undefined;
// Without a valid https link the tiles would lead nowhere: no section
const instagram = visibleSocials(siteContent.socials).find(
(social) => social.platform === 'instagram',
+5 -1
View File
@@ -9,6 +9,7 @@ import siteContent from '../content/siteContent';
import type { ShootTypeId } from '../content/types';
import { isShootTypeId } from '../lib/portfolioFilters';
import { visibleSocials } from '../lib/visibleSocials';
import useHydrated from '../hooks/useHydrated';
import { galleryImages, pageHead, structuredDataScript, webPage } from '../seo';
// ?shoot= from a filter or a "Bekijk meer …foto's" link: only a known shoot
@@ -42,7 +43,10 @@ export const Route = createFileRoute('/portfolio')({
// The portfolio (LAYOUT.md: Intro → Portfolio → Instagram): the photos with
// filters and lightbox, then the same Instagram block as on the homepage
function Portfolio() {
const { shoot } = Route.useSearch();
const { shoot: searched } = Route.useSearch();
// The filter only applies after hydration, so the prerendered HTML and the
// first browser render agree (BR-HYD-10)
const shoot = useHydrated() ? searched : undefined;
const navigate = useNavigate({ from: Route.fullPath });
const { intro, photos } = portfolioContent;
// Without a valid https link the tiles would lead nowhere: no section