Fixes the scroll to Contact from the price cards

Removing ?pakket= from the URL replaced the click's navigation before the
router scrolled to #contact, and told it not to scroll, so nothing
happened. The clean-up now asks the router to scroll there, below the
fixed header. The review carousel's placeholder is now the longest review
itself, so it matches the carousel's height at every width and no longer
shifts the target while the page scrolls past it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 00:59:20 +02:00
co-authored by Claude Opus 5.5
parent 0fce403ebc
commit 0b00b781b9
7 changed files with 87 additions and 17 deletions
@@ -728,3 +728,15 @@ De foto mag nog iets kleiner? 75% van huidige groote maken is denk ik goed. Het
**Context**: CONSTRUCTION - Unit 5 Code Generation (complete, awaiting approval)
---
## Unit 5 Contact — Bugs Reported on LAN, Fixed
**Timestamp**: 2026-10-21T01:30:00Z
**User Input**: "Er gebeurt niks als ik klik op de Boeken-knoppen. Geen effect en hij scrolt niet" / "Ik heb op lan getest" / "Zodra je klaar bent mag je weer comitten, pushen en deployen" / "Als ik op boek zwangerschap klik scrolt hij minder ver dan op de andere 2 knoppen" / "Wederom. Je mag comitten, pushen en deployen zodra je klaar bent"
**AI Response**: "Reproduced in real Chrome (CDP trace): the click pushed /?pakket=newborn#contact, our clean-up replaced it with hashScrollIntoView:false before the router's onRendered scroll, so no scroll happened (test still had unit 4, where #contact did not exist yet). Fixed: the clean-up navigation requests the hash scroll (smooth / auto under reduced motion); anchored sections get scroll-margin-top = header. Added an app test clicking 'Boek Newborn' asserting scrollIntoView on #contact (verified failing on the old code). Second bug: from the top card the review carousel loaded mid-scroll and its fixed placeholder height differed from the real height except at measured widths (+29px at 360, -44px at 600). Placeholder is now the longest review rendered like a slide plus the control height; no movement at 7 widths. CI run 555: deploy-test succeeded, Lighthouse job died on the Pi runner with exit -1 after pnpm install (infra). pnpm check green (238 tests, mobile 0.83, desktop 1.0). Committing, pushing, dispatching a test deploy as authorised."
**Context**: CONSTRUCTION - Unit 5 bug fixes (awaiting approval of unit 5)
---
@@ -50,9 +50,14 @@ Plan: [contact-code-generation-plan.md](../../plans/contact-code-generation-plan
First the form was moved into its own chunk, loaded when the section comes within 200 px of the screen, or at once when arriving via "Boek …". The remaining gap came from a new shared chunk (Chakra's slot-recipe factory, now used by three chunks) that the route had to fetch on page load: the price cards' `List` and the review slide's `Blockquote` were the only slot-recipe components on the route, so they became plain elements with the same styling, and the route no longer needs that chunk.
- **Placeholder** while the form loads: measured 604 px on phones, 502 px from `sm`.
## Bugs found by the owner on LAN, fixed (2026-10-21)
1. **"Boek …" did not scroll.** The click navigates to `/?pakket=<id>#contact` and the router scrolls to the hash in its `onRendered` step. Our clean-up navigation (removing `?pakket=`) ran first and passed `hashScrollIntoView: false`, so the router's last instruction was "don't scroll". Traced in real Chrome: `pushState`, `replaceState`, no `scrollIntoView`. The clean-up now asks the router to scroll to `#contact` (`smooth`, or `auto` under reduced motion). Anchored sections get `scroll-margin-top` equal to the header, so the section lands below the fixed header. A new app test clicks "Boek Newborn" on the price card and asserts the scroll to `#contact`; it fails with the old code and passes with the fix. jsdom tests missed it because `scrollIntoView` is a stub there.
2. **"Boek Zwangerschap" scrolled less far than the others.** Smooth scrolling fixes its target when it starts. From the top card the review carousel was not loaded yet and loaded during the scroll; its fixed-height placeholder only matched the carousel at the measured widths, so `#contact` moved by +29 px (360 px wide) or −44 px (600 px) mid-scroll. The placeholder is now the longest review rendered like a slide plus the control bar's height, which is as tall as the carousel at every width. Measured at 360, 390, 412, 600, 768, 1024 and 1440 px: no movement during the scroll; every button ends at the same place.
3. CI run 555: the Lighthouse job on the Pi runner stopped with exit code −1 right after `pnpm install`, before any measurement (runner/infra, not a check failure); rerun with the next deploy.
## Verification (`pnpm check`)
- Lint ✅, Prettier ✅, build ✅ (`ContactForm` in its own chunk, ±5.7 KB gzipped)
- Tests: 52 files, **237 passed**; 100% coverage on `src/lib/**`
- Tests: 52 files, **238 passed** (after the fixes); 100% coverage on `src/lib/**`
- Lighthouse home: mobile **0.83**, desktop **1.0**; accessibility, best practices, SEO **1.0**
- Visual check: 1440 and 390 with the overlay; 1440 with the form switched on locally (reverted before the build that was checked)
@@ -37,6 +37,8 @@ Plan: [lieve-woorden-code-generation-plan.md](../../plans/lieve-woorden-code-gen
The photo was too large on phones (it filled the screen). Now: phones max 180 px wide (±75% of a first 240 px step), tablets max 320 px, centred above the quote. Desktop grid `5fr 11fr` after reviewing screenshots of both, so the photo is ±75% of its earlier size (±395×495 px at 1440) and the whole block fits a ±1000 px high screen. Stacked slides align their content to the top (a short review no longer floats in the middle of the shared height) with a 1.25 rem gap between photo and text. Placeholder heights re-measured.
## Later change (unit 5)
The carousel's fixed-height placeholder was replaced by the longest review rendered like a slide plus the control bar's height, so it matches the carousel at every width (a mismatch moved `#contact` during a "Boek" scroll; see the unit 5 code summary).
The quote is a plain `figure`/`blockquote`/`figcaption` instead of Chakra's `Blockquote`: its slot recipe pulled a shared chunk into the route bundle on page load (see the unit 5 code summary, performance).
## Verification (`pnpm check`)
+22
View File
@@ -5,6 +5,7 @@ import {
RouterProvider,
} from '@tanstack/react-router';
import { render, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import lighthouseConfig from '../lighthouserc.cjs';
import ErrorPage from './components/StatusPage/ErrorPage';
@@ -163,6 +164,27 @@ describe('homepage', () => {
});
describe('homepage ?pakket=', () => {
it('a click on "Boek Newborn" scrolls to Contact and selects Newborn', async () => {
const scrolls = vi.spyOn(Element.prototype, 'scrollIntoView');
const user = userEvent.setup();
await renderApp('/');
await user.click(
await screen.findByRole('link', { name: 'Boek Newborn' }),
);
expect(
await screen.findByTestId('contact-form-shoot', undefined, {
timeout: 10_000,
}),
).toHaveValue('newborn');
await waitFor(() =>
expect(
scrolls.mock.contexts.some(
(element) => (element as Element).id === 'contact',
),
).toBe(true),
);
});
it('a "Boek Newborn" link selects Newborn, tidies the URL and focuses Contact', async () => {
const { router } = await renderApp('/?pakket=newborn#contact');
// The form is lazy; arriving via "Boek" loads it straight away
@@ -30,6 +30,8 @@ export default function HomeSection({
aria-labelledby={labelledBy}
data-testid={testId}
bg={tone === 'alt' ? 'paper.alt' : 'paper'}
// An anchor target (#contact) lands below the fixed header
scrollMarginTop={id ? 'header' : undefined}
py={spacing === 'tight' ? 'sectionYTight' : 'sectionY'}
>
<Container maxW={width === 'narrow' ? 'contentNarrow' : 'content'}>
@@ -1,5 +1,5 @@
import { lazy, Suspense, useEffect, useMemo, useState } from 'react';
import { Box } from '@chakra-ui/react';
import { Box, useMediaQuery } from '@chakra-ui/react';
import { useNavigate } from '@tanstack/react-router';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import ContactFormGate from '@/components/ContactForm/ContactFormGate';
@@ -72,8 +72,14 @@ export default function ContactSection({
}
}
// Then remove ?pakket= from the address bar (no extra history entry, no
// scroll) and continue keyboard and screen reader users here
// Then remove ?pakket= from the address bar (no extra history entry) and
// continue keyboard and screen reader users here. This navigation
// replaces the "Boek" click's before the router has scrolled for it, so
// it must ask the router to scroll to #contact itself.
const [reducedMotion] = useMediaQuery(
['(prefers-reduced-motion: reduce)'],
{ ssr: false },
);
useEffect(() => {
if (pakket === undefined) return;
void navigate({
@@ -82,9 +88,14 @@ export default function ContactSection({
hash: 'contact',
replace: true,
resetScroll: false,
hashScrollIntoView: false,
hashScrollIntoView: {
behavior: reducedMotion ? 'auto' : 'smooth',
block: 'start',
},
});
document.getElementById(TITLE_ID)?.focus({ preventScroll: true });
// Only when a new ?pakket= arrives, not when the motion setting changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pakket, navigate]);
const subject = mailSubject(chosenName);
@@ -17,16 +17,6 @@ const TestimonialCarousel = lazy(() => import('./TestimonialCarousel'));
const TITLE_ID = 'testimonials-title';
// Keeps about the space of the carousel while it loads, so the page below
// does not jump when it arrives (measured: ±685px on phones, ±790px on
// tablets, ±460px at 1024px, ±625px at 1440px)
const PLACEHOLDER_HEIGHT = {
base: '685px',
md: '790px',
lg: '460px',
xl: '625px',
};
type TestimonialsProps = {
content: HomeContent['testimonials'];
testimonials: Testimonial[];
@@ -61,12 +51,14 @@ export default function Testimonials({
<Box ref={ref}>
{inView ? (
<Suspense
fallback={<Box minH={PLACEHOLDER_HEIGHT} />}
fallback={
<CarouselPlaceholder testimonials={shown} />
}
>
<TestimonialCarousel testimonials={shown} />
</Suspense>
) : (
<Box minH={PLACEHOLDER_HEIGHT} />
<CarouselPlaceholder testimonials={shown} />
)}
</Box>
)}
@@ -74,3 +66,27 @@ export default function Testimonials({
</HomeSection>
);
}
// Stands in for the carousel until it has loaded: the longest review laid
// out exactly like a slide (same padding), plus the controls' height. That
// makes it as tall as the carousel at every screen width, so nothing below
// moves when the carousel takes its place, not even during a scroll to
// #contact that passes this section while it loads.
function CarouselPlaceholder({
testimonials,
}: {
testimonials: Testimonial[];
}) {
const longest = testimonials.reduce((a, b) =>
b.quote.length > a.quote.length ? b : a,
);
return (
<Box>
<Box ps={{ base: 0, sm: '1.5rem' }} pb={{ base: 0, sm: '1.5rem' }}>
<TestimonialSlide testimonial={longest} />
</Box>
{/* The control bar: 48px buttons below the same margin */}
<Box mt="clamp(2.5rem, 5vw, 4rem)" h="48px" />
</Box>
);
}