Adds browser tests and fixes hydration of the 404 page

The prerendered 404 page is served for other URLs, so its dehydrated match id
differs and the router renders the catch-all's pending component first. Without
one that render was empty, which gave React error 418 and duplicate head tags.
The tests run the built output in a real browser under the production CSP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 19:03:07 +01:00
co-authored by Claude Opus 5.5
parent 0c5d8b8f40
commit 8bf0000531
15 changed files with 1216 additions and 48 deletions
+31 -1
View File
@@ -1,7 +1,7 @@
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';
import { hydrateApp, hydrateAppAsStart } 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
@@ -71,3 +71,33 @@ describe('homepage ?pakket= on a direct load', () => {
expect(errors).toEqual([]);
});
});
// The prerendered 404 page is made for /404 and served for any unknown URL.
// Start does not recognise the catch-all match of another path (its id holds
// the path), so the browser renders that match itself. Its first render must
// be the page the HTML shows, or React reports a mismatch (BR-404-05, V12).
describe('404 page served for another URL', () => {
it.each(['/onbekend', '/404.html', '/over-mij/x'])(
'hydrates %s without a mismatch',
async (url) => {
const { errors } = await hydrateAppAsStart('/404', url);
expect(
await screen.findByRole('heading', {
name: 'Pagina niet gevonden',
}),
).toBeInTheDocument();
expect(errors).toEqual([]);
},
);
it('shows the section buttons after hydrating under /soorten-fotoshoots/', async () => {
const { errors } = await hydrateAppAsStart(
'/404',
'/soorten-fotoshoots/onbekend',
);
expect(
await screen.findByTestId('status-page-section-link'),
).toBeInTheDocument();
expect(errors).toEqual([]);
});
});