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
@@ -0,0 +1,49 @@
import { screen, waitFor } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { hydrateApp } from '@/test/hydrate';
import { renderApp } from '@/test/renderApp';
// The 404 page is prerendered for /404 and served for every unknown URL, so
// the first browser render must not depend on the real path (BR-404-04, 05)
const homeLink = () => screen.queryByTestId('status-page-home-link');
const sectionLink = () => screen.queryByTestId('status-page-section-link');
describe('NotFound while hydrating', () => {
it('shows the section buttons only after hydrating under /soorten-fotoshoots/', async () => {
const { container, errors } = await hydrateApp(
'/404',
'/soorten-fotoshoots/onbekend',
);
await waitFor(() => expect(sectionLink()).toBeInTheDocument());
expect(sectionLink()).toHaveAttribute('href', '/soorten-fotoshoots');
expect(homeLink()).toHaveAttribute('href', '/');
expect(container).toHaveTextContent('Pagina niet gevonden');
expect(errors).toEqual([]);
});
it('keeps one button on an unknown URL outside the section', async () => {
const { container, errors } = await hydrateApp('/404', '/onbekend');
expect(
await screen.findByRole('link', { name: 'Terug naar home' }),
).toBeInTheDocument();
expect(sectionLink()).not.toBeInTheDocument();
expect(container).toHaveTextContent('Pagina niet gevonden');
expect(errors).toEqual([]);
});
});
describe('NotFound on a plain mount', () => {
it('shows the section buttons at once under /soorten-fotoshoots/', async () => {
await renderApp('/soorten-fotoshoots/onbekend');
expect(sectionLink()).toBeInTheDocument();
expect(homeLink()).toBeInTheDocument();
});
it('shows one button at once elsewhere', async () => {
await renderApp('/onbekend');
expect(sectionLink()).not.toBeInTheDocument();
expect(
screen.getByRole('link', { name: 'Terug naar home' }),
).toBeInTheDocument();
});
});
+5 -1
View File
@@ -1,4 +1,5 @@
import { useRouterState } from '@tanstack/react-router';
import useHydrated from '@/hooks/useHydrated';
import { isShootSectionPath } from '@/lib/isShootSectionPath';
import LinkButton from '../LinkButton';
import StatusPage from './StatusPage';
@@ -9,6 +10,9 @@ import StatusPage from './StatusPage';
// Onder /soorten-fotoshoots/ komt er een knop naar het overzicht bij
// (FR-ST-14).
export default function NotFound() {
// De prerender is gemaakt voor /404; het echte pad telt pas na de
// hydratatie, anders verschilt de eerste render van de HTML (BR-404-04)
const hydrated = useHydrated();
const pathname = useRouterState({
select: (routerState) => routerState.location.pathname,
});
@@ -20,7 +24,7 @@ export default function NotFound() {
<StatusPage
title="Pagina niet gevonden"
actions={
isShootSectionPath(pathname) ? (
hydrated && isShootSectionPath(pathname) ? (
<>
<LinkButton
to="/soorten-fotoshoots"