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
@@ -1,5 +1,6 @@
import { act, fireEvent, render, renderHook } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { hydrate, renderToString } from '@/test/hydrate';
import useHeroSlider from './useHeroSlider';
// De automatische wissel komt in de browser van animationend op de
@@ -84,3 +85,74 @@ describe('useHeroSlider', () => {
expect(slider).toMatchObject({ stopped: false, paused: false });
});
});
// In de HTML is het tabblad zichtbaar en loopt autoplay; pas na de hydratatie
// telt wat de browser meldt (BR-HYD-09)
describe('useHeroSlider tijdens het hydrateren', () => {
const seen: { paused: boolean; autoplay: boolean }[] = [];
function Probe() {
const { paused, autoplay } = useHeroSlider(3);
seen.push({ paused, autoplay });
return (
<p>
{paused ? 'gepauzeerd' : 'loopt'}
{autoplay ? ' autoplay' : ' stil'}
</p>
);
}
it('geeft in de serverrender een zichtbaar tabblad', () => {
vi.spyOn(document, 'hidden', 'get').mockReturnValue(true);
expect(renderToString(<Probe />)).toContain('loopt');
});
it('leest document.hidden pas na het hydrateren', () => {
vi.spyOn(document, 'hidden', 'get').mockReturnValue(true);
seen.length = 0;
const { container, errors } = hydrate(<Probe />);
expect(seen[0].paused).toBe(false);
expect(container).toHaveTextContent('gepauzeerd');
expect(errors).toEqual([]);
});
it('volgt visibilitychange', () => {
const hidden = vi.spyOn(document, 'hidden', 'get');
hidden.mockReturnValue(false);
const { container } = hydrate(<Probe />);
expect(container).toHaveTextContent('loopt');
act(() => {
hidden.mockReturnValue(true);
document.dispatchEvent(new Event('visibilitychange'));
});
expect(container).toHaveTextContent('gepauzeerd');
});
it('leest document.hidden meteen bij een latere mount', () => {
vi.spyOn(document, 'hidden', 'get').mockReturnValue(true);
seen.length = 0;
render(<Probe />);
expect(seen[0].paused).toBe(true);
});
it('gaat in de eerste render uit van autoplay, ook bij verminderde beweging', () => {
vi.spyOn(window, 'matchMedia').mockImplementation(
(query: string) =>
({
matches: query.includes('reduce'),
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
dispatchEvent: () => false,
addEventListener: () => {},
removeEventListener: () => {},
}) as MediaQueryList,
);
seen.length = 0;
const { container } = hydrate(<Probe />);
expect(seen[0].autoplay).toBe(true);
expect(container).toHaveTextContent('stil');
});
});