Loads the light logo after the page load

Lazy loading saved its bytes during page load, but left the logo empty for a
moment when navigating to the homepage on a wide screen. Also adds the second
unit's code summary and the shared docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 01:56:13 +01:00
co-authored by Claude Opus 5.5
parent b965b8a227
commit b5fd83256d
14 changed files with 176 additions and 37 deletions
+61 -14
View File
@@ -205,20 +205,67 @@ describe('/contact', () => {
});
describe("logo's", () => {
it('vraagt het lichte logo alleen op de homepage op', async () => {
for (const path of Object.keys(sitePages)) {
const requests = track();
const { page } = await openPage(server.origin + path, {
width: 1350,
height: 940,
prepare: requests.prepare,
});
await page.waitForLoadState('networkidle');
const light = requests.log.filter((entry) =>
/\/logo-light-/.test(entry.url),
);
expect(light.length, path).toBe(path === '/' ? 1 : 0);
}
// BR-PRE-05, V-D7: buiten de homepage vraagt de browser het lichte logo pas
// na de load-gebeurtenis op (daarna één keer, zodat een klik naar / het
// logo niet laat knipperen). Een navigatie voor de load kan nog even knipperen.
it.each([1350, 412])(
'vraagt het lichte logo buiten de homepage pas na de load op (%i px)',
async (width) => {
for (const path of Object.keys(sitePages)) {
const requests = track();
const { page } = await openPage(server.origin + path, {
width,
height: 940,
prepare: requests.prepare,
});
await page.waitForLoadState('networkidle');
const light = requests.log.filter((entry) =>
/\/logo-light-/.test(entry.url),
);
expect(light.length, path).toBe(1);
expect(light[0].beforeLoad, path).toBe(path === '/');
}
},
);
it('laat het logo niet knipperen bij een klik naar de homepage na de load (1350 px)', async () => {
const { page } = await openPage(server.origin + '/over-mij', {
width: 1350,
height: 940,
});
await page.waitForLoadState('networkidle');
await waitForHydration(page);
await page.evaluate(() => {
const w = window as unknown as { __frames: string[] };
w.__frames = [];
const tick = () => {
w.__frames.push(
[...document.querySelectorAll('header img')]
.map((img) => {
const rect = img.getBoundingClientRect();
return `${(img as HTMLImageElement).complete}|${Math.round(rect.width)}`;
})
.join(';'),
);
requestAnimationFrame(tick);
};
tick();
});
await page.locator('[data-testid="nav-logo-link"]').click();
await page.waitForURL(server.origin + '/');
await page.waitForTimeout(800);
const frames = await page.evaluate(
() => (window as unknown as { __frames: string[] }).__frames,
);
// Een getoond logo (breedte > 0) dat nog niet geladen is, is een flits
const flashes = frames.filter((frame) =>
frame
.split(';')
.some(
(logo) => logo.startsWith('false|') && !logo.endsWith('|0'),
),
);
expect(flashes).toEqual([]);
});
});
@@ -1,6 +1,7 @@
import { fireEvent, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { act } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { axeResults } from '@/test/axe';
import { cssRulesFor } from '@/test/cssRules';
import { mockViewport } from '@/test/navViewport';
@@ -26,6 +27,24 @@ const panelLink = (text: string) =>
.find((link) => link.textContent === text)!;
describe('NavigationBar', () => {
it('houdt het lichte logo lui tot de pagina geladen is, behalve op home (BR-PRE-05)', async () => {
const readyState = vi
.spyOn(document, 'readyState', 'get')
.mockReturnValue('interactive');
const { container } = await renderWithProviders(<NavigationBar />, {
path: '/over-mij',
});
const light = () => container.querySelectorAll('header img')[1];
expect(light()).toHaveAttribute('loading', 'lazy');
act(() => {
readyState.mockReturnValue('complete');
window.dispatchEvent(new Event('load'));
});
expect(light()).not.toHaveAttribute('loading');
readyState.mockRestore();
});
it('heeft het logo als link naar home', async () => {
await renderWithProviders(<NavigationBar />, { path: '/portfolio' });
expect(
@@ -12,6 +12,7 @@ import { NoScriptMenuOpen } from './NoScriptNav';
import NavSubmenu from './NavSubmenu';
import { hasChildren, mainNav } from '@/navigation';
import RouterLink from '../RouterLink';
import usePageLoaded from '@/hooks/usePageLoaded';
import useScrolledPast from '@/hooks/useScrolledPast';
import { HEADER_ID, MOBILE_NAV_ID } from '../NoScript/noScriptCss';
import { isSectionCurrent } from '@/lib/navCurrent';
@@ -49,6 +50,7 @@ export default function NavigationBar() {
select: (routerState) => routerState.location.pathname,
});
const isHome = pathname === '/';
const pageLoaded = usePageLoaded();
// Elke wissel van pagina sluit de menu's (ook de terugknop), maar niet
// bij de eerste render
@@ -139,8 +141,13 @@ export default function NavigationBar() {
htmlWidth={500}
htmlHeight={500}
// Not shown on pages with a solid header, so
// not fetched there (BR-PRE-05)
loading={isHome ? undefined : 'lazy'}
// it must not compete with the page's own
// photos until the page has loaded. Then it
// loads anyway: a lazy hidden image would
// flash on a client navigation to / (BR-PRE-05)
loading={
isHome || pageLoaded ? undefined : 'lazy'
}
display={overlay('none', 'block')}
/>
</RouterLink>