From c4348ecd3a82db199fd640a97d82cda04d707c85 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Tue, 3 Nov 2026 19:49:22 +0100 Subject: [PATCH] Counts only visible headings in the 404 hydration test On the catch-all 404 page the router shows its pending copy for 500 ms while the server copy stays hidden with display:none. The test counted h1 elements in that window and found the hidden one on the faster PC runner. It now counts what a visitor or screen reader gets, then checks that the hidden copy is gone. Co-Authored-By: Claude Opus 5.5 --- web/e2e/hydration.e2e.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/e2e/hydration.e2e.ts b/web/e2e/hydration.e2e.ts index 590f397..26133b5 100644 --- a/web/e2e/hydration.e2e.ts +++ b/web/e2e/hydration.e2e.ts @@ -44,10 +44,18 @@ describe.each(widths)('hydratatie op %i px', (width) => { expect(opened.violations).toEqual([]); // Na de hydratatie nog steeds één titel en hoogstens één robots (V11) + // en één kop 1 voor wie de pagina ziet of hoort. Op een 404 staat + // er een tijdje (tot pendingMinMs, 0,5 s) naast de echte kop een + // kopie van de serverpagina in een display:none-sectie: die ziet + // en hoort niemand, maar querySelectorAll telt hem wel mee. const counts = await page.evaluate(() => ({ titles: document.querySelectorAll('title').length, robots: document.querySelectorAll('meta[name="robots"]').length, - h1: document.querySelectorAll('h1').length, + h1: [...document.querySelectorAll('h1')].filter( + (heading) => + heading.checkVisibility() && + !heading.closest('[aria-hidden="true"]'), + ).length, })); const noindex = notFoundPaths.includes(path) || path === '/privacyverklaring'; @@ -56,6 +64,10 @@ describe.each(widths)('hydratatie op %i px', (width) => { robots: noindex ? 1 : 0, h1: 1, }); + // Is de wissel klaar, dan is ook de verborgen kopie weg + await eventually(() => + page.evaluate(() => document.querySelectorAll('h1').length), + ).toBe(1); }, ); }); -- 2.39.5