Moves the app to TanStack Start with prerendering
Every page is now built as HTML from sitePages.ts, with a catch-all route for 404.html. Hooks that read the browser during render are safe for prerendering. The script step that keeps the CSP intact follows, so this build still has inline scripts and is not deployable yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -626,7 +626,10 @@ describe('pagina-register', () => {
|
||||
|
||||
it('bevat precies de routes van de route tree', async () => {
|
||||
const { router } = await renderApp('/');
|
||||
const routePaths = Object.keys(router.routesByPath).sort();
|
||||
// De vangroute (404) is geen pagina en staat niet in het register
|
||||
const routePaths = Object.keys(router.routesByPath)
|
||||
.filter((path) => path !== '/$')
|
||||
.sort();
|
||||
expect(Object.keys(sitePages).sort()).toEqual(routePaths);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { StrictMode, startTransition } from 'react';
|
||||
import { hydrateRoot } from 'react-dom/client';
|
||||
import { StartClient } from '@tanstack/react-start/client';
|
||||
import { startSentry } from './monitoring/sentry';
|
||||
|
||||
// Foutmeldingen naar Sentry, alleen op test en productie (M1). Dit bestand
|
||||
// draait alleen in de browser, dus niet tijdens het prerenderen, en loopt voor
|
||||
// op het hydrateren zodat ook vroege fouten gemeld worden.
|
||||
startSentry();
|
||||
|
||||
startTransition(() => {
|
||||
hydrateRoot(
|
||||
document,
|
||||
<StrictMode>
|
||||
<StartClient />
|
||||
</StrictMode>,
|
||||
);
|
||||
});
|
||||
@@ -6,13 +6,12 @@ const SCRIPT_ELEMENT_ID = 'umami-analytics-script';
|
||||
// Bezoekersstatistieken zonder cookies (M6). Alleen op een bekende host, met
|
||||
// de website van die omgeving; data-domains telt nergens anders mee en
|
||||
// data-do-not-track respecteert de Do Not Track-instelling van de browser.
|
||||
export default function UmamiAnalytics({
|
||||
hostname = window.location.hostname,
|
||||
}: {
|
||||
hostname?: string;
|
||||
}) {
|
||||
export default function UmamiAnalytics({ hostname }: { hostname?: string }) {
|
||||
useEffect(() => {
|
||||
const monitoring = monitoringFor(hostname);
|
||||
// Read here, not as a default parameter: there is no window while
|
||||
// prerendering
|
||||
const host = hostname ?? window.location.hostname;
|
||||
const monitoring = monitoringFor(host);
|
||||
if (!monitoring || document.getElementById(SCRIPT_ELEMENT_ID)) return;
|
||||
|
||||
const script = document.createElement('script');
|
||||
@@ -20,7 +19,7 @@ export default function UmamiAnalytics({
|
||||
script.src = `${umamiOrigin}/script.js`;
|
||||
script.defer = true;
|
||||
script.dataset.websiteId = monitoring.umamiWebsiteId;
|
||||
script.dataset.domains = hostname;
|
||||
script.dataset.domains = host;
|
||||
script.dataset.doNotTrack = 'true';
|
||||
document.head.appendChild(script);
|
||||
|
||||
|
||||
@@ -40,12 +40,16 @@ describe('DeferredImage', () => {
|
||||
});
|
||||
|
||||
it('waits for the page load event, even when already in view', async () => {
|
||||
vi.spyOn(document, 'readyState', 'get').mockReturnValue('interactive');
|
||||
const readyState = vi
|
||||
.spyOn(document, 'readyState', 'get')
|
||||
.mockReturnValue('interactive');
|
||||
await renderWithProviders(<DeferredImage image={image} />);
|
||||
const img = screen.getByRole('img', { name: 'Een foto' });
|
||||
expect(img).not.toHaveAttribute('src');
|
||||
|
||||
act(() => {
|
||||
// The browser is 'complete' by the time the load event fires
|
||||
readyState.mockReturnValue('complete');
|
||||
window.dispatchEvent(new Event('load'));
|
||||
});
|
||||
expect(img).toHaveAttribute('src', '/foto.jpg');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useState, useSyncExternalStore } from 'react';
|
||||
import { useMediaQuery } from '@chakra-ui/react';
|
||||
import useSwipe from '@/hooks/useSwipe';
|
||||
import { wrapIndex } from '@/lib/wrapIndex';
|
||||
@@ -12,6 +12,11 @@ import { wrapIndex } from '@/lib/wrapIndex';
|
||||
// leest een nieuwe naam van de knop met focus niet altijd voor.
|
||||
export type HeroAnnouncement = 'slide' | 'paused' | 'playing' | null;
|
||||
|
||||
const subscribeVisibility = (onChange: () => void) => {
|
||||
document.addEventListener('visibilitychange', onChange);
|
||||
return () => document.removeEventListener('visibilitychange', onChange);
|
||||
};
|
||||
|
||||
export default function useHeroSlider(count: number) {
|
||||
const [index, setIndex] = useState(0);
|
||||
const [announcement, setAnnouncement] = useState<HeroAnnouncement>(null);
|
||||
@@ -19,23 +24,13 @@ export default function useHeroSlider(count: number) {
|
||||
const [stopped, setStopped] = useState(false);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [focused, setFocused] = useState(false);
|
||||
const [hidden, setHidden] = useState(() => document.hidden);
|
||||
const [reducedMotion] = useMediaQuery(
|
||||
['(prefers-reduced-motion: reduce)'],
|
||||
{
|
||||
ssr: false,
|
||||
},
|
||||
// Server and hydrating render say "visible", like the HTML
|
||||
const hidden = useSyncExternalStore(
|
||||
subscribeVisibility,
|
||||
() => document.hidden,
|
||||
() => false,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const onVisibilityChange = () => setHidden(document.hidden);
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
return () =>
|
||||
document.removeEventListener(
|
||||
'visibilitychange',
|
||||
onVisibilityChange,
|
||||
);
|
||||
}, []);
|
||||
const [reducedMotion] = useMediaQuery(['(prefers-reduced-motion: reduce)']);
|
||||
|
||||
// Als de API minder slides teruggeeft dan de huidige index, begin vooraan.
|
||||
const active = index < count ? index : 0;
|
||||
|
||||
@@ -32,11 +32,9 @@ export default function NavigationBar() {
|
||||
const submenuToggleRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
// Het mobiele menu bestaat alleen onder lg; wordt het scherm breder, dan
|
||||
// sluit de reducer het. Eerste render kan undefined geven: telt als mobiel.
|
||||
const isDesktop = useBreakpointValue(
|
||||
{ base: false, lg: true },
|
||||
{ ssr: false },
|
||||
);
|
||||
// sluit de reducer het. De eerste render geeft de waarde van `base` (zo ook
|
||||
// in de voorgerenderde HTML): telt als mobiel.
|
||||
const isDesktop = useBreakpointValue({ base: false, lg: true });
|
||||
useEffect(() => {
|
||||
dispatch({ type: 'viewport', isDesktop: !!isDesktop });
|
||||
}, [isDesktop]);
|
||||
|
||||
@@ -41,10 +41,7 @@ export default function ContactSection({
|
||||
// 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 },
|
||||
);
|
||||
const [reducedMotion] = useMediaQuery(['(prefers-reduced-motion: reduce)']);
|
||||
useEffect(() => {
|
||||
if (pakket === undefined) return;
|
||||
void navigate({
|
||||
|
||||
@@ -27,10 +27,7 @@ export default function TestimonialCarousel({
|
||||
testimonials: Testimonial[];
|
||||
}) {
|
||||
const count = testimonials.length;
|
||||
const [reducedMotion] = useMediaQuery(
|
||||
['(prefers-reduced-motion: reduce)'],
|
||||
{ ssr: false },
|
||||
);
|
||||
const [reducedMotion] = useMediaQuery(['(prefers-reduced-motion: reduce)']);
|
||||
// Empty on load; filled only by a change, so nothing is read out then
|
||||
const [announcement, setAnnouncement] = useState('');
|
||||
const carousel = useCarousel({
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
const subscribeNoop = () => () => {};
|
||||
|
||||
// False while prerendering and during the hydrating render, true afterwards
|
||||
// (and at once for components that mount later). Same behaviour as the
|
||||
// useHydrated that the router keeps internally.
|
||||
export default function useHydrated() {
|
||||
return useSyncExternalStore(
|
||||
subscribeNoop,
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
||||
|
||||
const noopSubscribe = () => () => {};
|
||||
|
||||
type UseInViewOptions = {
|
||||
threshold?: number;
|
||||
@@ -8,21 +10,25 @@ type UseInViewOptions = {
|
||||
};
|
||||
|
||||
// Tells whether an element has come into (or near) the viewport, once.
|
||||
// Without IntersectionObserver the element counts as in view right away, so
|
||||
// content is never left hidden or unloaded.
|
||||
// Without IntersectionObserver the element counts as in view (from the first
|
||||
// render after hydration), so content is never left hidden or unloaded.
|
||||
export default function useInView<T extends Element>({
|
||||
threshold = 0,
|
||||
rootMargin = '0px',
|
||||
skip = false,
|
||||
}: UseInViewOptions = {}) {
|
||||
const ref = useRef<T>(null);
|
||||
const supported = typeof IntersectionObserver !== 'undefined';
|
||||
// The server cannot know, so prerender and hydration both assume support
|
||||
const unsupported = useSyncExternalStore(
|
||||
noopSubscribe,
|
||||
() => typeof IntersectionObserver === 'undefined',
|
||||
() => false,
|
||||
);
|
||||
const [intersected, setIntersected] = useState(false);
|
||||
const immediate = skip || !supported;
|
||||
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element || immediate || intersected) return;
|
||||
if (!element || skip || unsupported || intersected) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
@@ -36,7 +42,7 @@ export default function useInView<T extends Element>({
|
||||
observer.observe(element);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [immediate, intersected, threshold, rootMargin]);
|
||||
}, [skip, unsupported, intersected, threshold, rootMargin]);
|
||||
|
||||
return { ref, inView: immediate || intersected };
|
||||
return { ref, inView: skip || intersected || unsupported };
|
||||
}
|
||||
|
||||
@@ -9,11 +9,15 @@ describe('usePageLoaded', () => {
|
||||
});
|
||||
|
||||
it('turns true on the load event', () => {
|
||||
vi.spyOn(document, 'readyState', 'get').mockReturnValue('interactive');
|
||||
const readyState = vi
|
||||
.spyOn(document, 'readyState', 'get')
|
||||
.mockReturnValue('interactive');
|
||||
const { result } = renderHook(() => usePageLoaded());
|
||||
expect(result.current).toBe(false);
|
||||
|
||||
act(() => {
|
||||
// The browser is 'complete' by the time the load event fires
|
||||
readyState.mockReturnValue('complete');
|
||||
window.dispatchEvent(new Event('load'));
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
// True once the window's load event has fired (or had already fired).
|
||||
const subscribe = (onChange: () => void) => {
|
||||
window.addEventListener('load', onChange, { once: true });
|
||||
return () => window.removeEventListener('load', onChange);
|
||||
};
|
||||
|
||||
// True once the window's load event has fired (or had already fired). While
|
||||
// prerendering and hydrating it is false, like the HTML.
|
||||
export default function usePageLoaded() {
|
||||
const [loaded, setLoaded] = useState(
|
||||
return useSyncExternalStore(
|
||||
subscribe,
|
||||
() => document.readyState === 'complete',
|
||||
() => false,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (loaded) return;
|
||||
const onLoad = () => setLoaded(true);
|
||||
window.addEventListener('load', onLoad, { once: true });
|
||||
return () => window.removeEventListener('load', onLoad);
|
||||
}, [loaded]);
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,11 @@ describe('useReveal', () => {
|
||||
mockReducedMotion();
|
||||
renderProbe();
|
||||
expect(screen.getByTestId('probe')).toHaveTextContent('visible');
|
||||
expect(FakeObserver.instances).toHaveLength(0);
|
||||
// The first render still assumes motion is fine (as the prerendered
|
||||
// HTML does), so an observer may start; it is stopped again at once
|
||||
expect(
|
||||
FakeObserver.instances.every((observer) => observer.disconnected),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('stays hidden until the element scrolls into view, then stops observing', () => {
|
||||
|
||||
@@ -6,10 +6,7 @@ import useInView from './useInView';
|
||||
// right at the bottom edge. When the visitor prefers reduced motion the
|
||||
// element counts as visible right away.
|
||||
export default function useReveal<T extends Element>() {
|
||||
const [reducedMotion] = useMediaQuery(
|
||||
['(prefers-reduced-motion: reduce)'],
|
||||
{ ssr: false },
|
||||
);
|
||||
const [reducedMotion] = useMediaQuery(['(prefers-reduced-motion: reduce)']);
|
||||
const { ref, inView } = useInView<T>({
|
||||
threshold: 0.12,
|
||||
rootMargin: '0px 0px -60px 0px',
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import { StrictMode } from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { RouterProvider, createRouter } from '@tanstack/react-router';
|
||||
import { routeTree } from './routeTree.gen';
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import system from './theme.ts';
|
||||
import ErrorPage from './components/StatusPage/ErrorPage';
|
||||
import { startSentry } from './monitoring/sentry';
|
||||
|
||||
import '@fontsource/jost/300.css';
|
||||
import '@fontsource/jost/400.css';
|
||||
import '@fontsource/jost/500.css';
|
||||
import '@fontsource/marcellus/400.css';
|
||||
|
||||
// Foutmeldingen naar Sentry, alleen op test en productie (M1)
|
||||
startSentry();
|
||||
|
||||
// Create a new router instance
|
||||
const router = createRouter({
|
||||
routeTree,
|
||||
// Nieuwe pagina begint bovenaan; terug/vooruit herstelt de positie (FR-08)
|
||||
scrollRestoration: true,
|
||||
// Fout in een pagina: foutpagina binnen de shell (FR-10)
|
||||
defaultErrorComponent: ErrorPage,
|
||||
});
|
||||
|
||||
// Register the router instance for type safety
|
||||
declare module '@tanstack/react-router' {
|
||||
interface Register {
|
||||
router: typeof router;
|
||||
}
|
||||
}
|
||||
|
||||
// De statische head-tags uit index.html zijn alleen voor crawlers zonder
|
||||
// JavaScript. Vanaf hier beheren de routes ze, dus voorkom dubbele tags.
|
||||
document.querySelectorAll('head [data-fallback]').forEach((el) => el.remove());
|
||||
|
||||
// Render the app
|
||||
const rootElement = document.getElementById('root')!;
|
||||
if (!rootElement.innerHTML) {
|
||||
const root = ReactDOM.createRoot(rootElement);
|
||||
root.render(
|
||||
<StrictMode>
|
||||
{/* De site is alleen licht; de _dark-waarden in het thema blijven
|
||||
staan voor een eventuele donkere modus later */}
|
||||
<ChakraProvider value={system}>
|
||||
<RouterProvider router={router} />
|
||||
</ChakraProvider>
|
||||
</StrictMode>,
|
||||
);
|
||||
}
|
||||
@@ -3,8 +3,9 @@ import { shootNavItems } from './lib/shootNavItems.ts';
|
||||
import type { FileRoutesByTo } from './routeTree.gen.ts';
|
||||
|
||||
// Menu's verwijzen naar routes, en routes zijn code: het CMS kan geen
|
||||
// pagina's toevoegen. Een tikfout in `to` is daardoor een typefout.
|
||||
export type RoutePath = keyof FileRoutesByTo;
|
||||
// pagina's toevoegen. Een tikfout in `to` is daardoor een typefout. De
|
||||
// vangroute voor onbekende URL's is geen pagina: niet in menu's en register.
|
||||
export type RoutePath = Exclude<keyof FileRoutesByTo, '/$'>;
|
||||
|
||||
export interface NavItem {
|
||||
to: RoutePath;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as IndexRouteImport } from './routes/index'
|
||||
import { Route as SplatRouteImport } from './routes/$'
|
||||
import { Route as ContactRouteImport } from './routes/contact'
|
||||
import { Route as OverMijRouteImport } from './routes/over-mij'
|
||||
import { Route as PortfolioRouteImport } from './routes/portfolio'
|
||||
@@ -26,6 +27,11 @@ const IndexRoute = IndexRouteImport.update({
|
||||
path: '/',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const SplatRoute = SplatRouteImport.update({
|
||||
id: '/$',
|
||||
path: '/$',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const ContactRoute = ContactRouteImport.update({
|
||||
id: '/contact',
|
||||
path: '/contact',
|
||||
@@ -83,6 +89,7 @@ const SoortenFotoshootsZwangerschapRoute =
|
||||
|
||||
export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexRoute
|
||||
'/$': typeof SplatRoute
|
||||
'/contact': typeof ContactRoute
|
||||
'/over-mij': typeof OverMijRoute
|
||||
'/portfolio': typeof PortfolioRoute
|
||||
@@ -96,6 +103,7 @@ export interface FileRoutesByFullPath {
|
||||
}
|
||||
export interface FileRoutesByTo {
|
||||
'/': typeof IndexRoute
|
||||
'/$': typeof SplatRoute
|
||||
'/contact': typeof ContactRoute
|
||||
'/over-mij': typeof OverMijRoute
|
||||
'/portfolio': typeof PortfolioRoute
|
||||
@@ -110,6 +118,7 @@ export interface FileRoutesByTo {
|
||||
export interface FileRoutesById {
|
||||
__root__: typeof rootRouteImport
|
||||
'/': typeof IndexRoute
|
||||
'/$': typeof SplatRoute
|
||||
'/contact': typeof ContactRoute
|
||||
'/over-mij': typeof OverMijRoute
|
||||
'/portfolio': typeof PortfolioRoute
|
||||
@@ -125,6 +134,7 @@ export interface FileRouteTypes {
|
||||
fileRoutesByFullPath: FileRoutesByFullPath
|
||||
fullPaths:
|
||||
| '/'
|
||||
| '/$'
|
||||
| '/contact'
|
||||
| '/over-mij'
|
||||
| '/portfolio'
|
||||
@@ -138,6 +148,7 @@ export interface FileRouteTypes {
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to:
|
||||
| '/'
|
||||
| '/$'
|
||||
| '/contact'
|
||||
| '/over-mij'
|
||||
| '/portfolio'
|
||||
@@ -151,6 +162,7 @@ export interface FileRouteTypes {
|
||||
id:
|
||||
| '__root__'
|
||||
| '/'
|
||||
| '/$'
|
||||
| '/contact'
|
||||
| '/over-mij'
|
||||
| '/portfolio'
|
||||
@@ -165,6 +177,7 @@ export interface FileRouteTypes {
|
||||
}
|
||||
export interface RootRouteChildren {
|
||||
IndexRoute: typeof IndexRoute
|
||||
SplatRoute: typeof SplatRoute
|
||||
ContactRoute: typeof ContactRoute
|
||||
OverMijRoute: typeof OverMijRoute
|
||||
PortfolioRoute: typeof PortfolioRoute
|
||||
@@ -186,6 +199,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof IndexRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/$': {
|
||||
id: '/$'
|
||||
path: '/$'
|
||||
fullPath: '/$'
|
||||
preLoaderRoute: typeof SplatRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/contact': {
|
||||
id: '/contact'
|
||||
path: '/contact'
|
||||
@@ -261,6 +281,7 @@ declare module '@tanstack/react-router' {
|
||||
|
||||
const rootRouteChildren: RootRouteChildren = {
|
||||
IndexRoute: IndexRoute,
|
||||
SplatRoute: SplatRoute,
|
||||
ContactRoute: ContactRoute,
|
||||
OverMijRoute: OverMijRoute,
|
||||
PortfolioRoute: PortfolioRoute,
|
||||
@@ -275,3 +296,12 @@ const rootRouteChildren: RootRouteChildren = {
|
||||
export const routeTree = rootRouteImport
|
||||
._addFileChildren(rootRouteChildren)
|
||||
._addFileTypes<FileRouteTypes>()
|
||||
|
||||
import type { getRouter } from './router.tsx'
|
||||
import type { createStart } from '@tanstack/react-start'
|
||||
declare module '@tanstack/react-start' {
|
||||
interface Register {
|
||||
ssr: true
|
||||
router: Awaited<ReturnType<typeof getRouter>>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { createRouter } from '@tanstack/react-router';
|
||||
import { routeTree } from './routeTree.gen';
|
||||
import ErrorPage from './components/StatusPage/ErrorPage';
|
||||
|
||||
// Eén set opties voor de app en voor de tests (renderApp)
|
||||
export function routerOptions() {
|
||||
return {
|
||||
routeTree,
|
||||
// Nieuwe pagina begint bovenaan; terug/vooruit herstelt de positie (FR-08)
|
||||
scrollRestoration: true,
|
||||
// Fout in een pagina: foutpagina binnen de shell (FR-10)
|
||||
defaultErrorComponent: ErrorPage,
|
||||
};
|
||||
}
|
||||
|
||||
// Start roept dit aan voor elke render: op de server per prerender-verzoek,
|
||||
// in de browser één keer
|
||||
export function getRouter() {
|
||||
return createRouter(routerOptions());
|
||||
}
|
||||
|
||||
// Register the router instance for type safety
|
||||
declare module '@tanstack/react-router' {
|
||||
interface Register {
|
||||
router: ReturnType<typeof getRouter>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import NotFound from '../components/StatusPage/NotFound';
|
||||
|
||||
// Vangt elke onbekende URL op en wordt als 404.html voorgerenderd (BR-404-01).
|
||||
// Geen head() en geen notFound(): Start laat de build falen bij een niet-OK
|
||||
// antwoord, en NotFound zet zelf titel en noindex.
|
||||
export const Route = createFileRoute('/$')({
|
||||
component: NotFound,
|
||||
});
|
||||
@@ -1,10 +1,18 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { createRootRoute, HeadContent } from '@tanstack/react-router';
|
||||
import type { ReactNode } from 'react';
|
||||
import { createRootRoute, HeadContent, Scripts } from '@tanstack/react-router';
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import AppShell from '../components/AppShell';
|
||||
import ErrorPage from '../components/StatusPage/ErrorPage';
|
||||
import NotFound from '../components/StatusPage/NotFound';
|
||||
import siteContent from '../content/siteContent';
|
||||
import { siteHead } from '../seo';
|
||||
import system from '../theme';
|
||||
|
||||
import '@fontsource/jost/300.css';
|
||||
import '@fontsource/jost/400.css';
|
||||
import '@fontsource/jost/500.css';
|
||||
import '@fontsource/marcellus/400.css';
|
||||
|
||||
// Devtools alleen tijdens het ontwikkelen; ze komen niet in de productiebuild
|
||||
const RouterDevtools = import.meta.env.DEV
|
||||
@@ -15,10 +23,24 @@ const RouterDevtools = import.meta.env.DEV
|
||||
)
|
||||
: () => null;
|
||||
|
||||
// Het hele document: Start rendert dit op de server en hydrateert het in de
|
||||
// browser. Titel en meta-tags van de actieve route komen via HeadContent.
|
||||
const RootDocument = ({ children }: { children: ReactNode }) => (
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<HeadContent />
|
||||
</head>
|
||||
<body>
|
||||
{/* De site is alleen licht; de _dark-waarden in het thema blijven
|
||||
staan voor een eventuele donkere modus later */}
|
||||
<ChakraProvider value={system}>{children}</ChakraProvider>
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
const RootLayout = () => (
|
||||
<>
|
||||
{/* Titel en meta-tags van de actieve route; React zet ze in <head> */}
|
||||
<HeadContent />
|
||||
<AppShell />
|
||||
<Suspense>
|
||||
<RouterDevtools />
|
||||
@@ -27,7 +49,25 @@ const RootLayout = () => (
|
||||
);
|
||||
|
||||
export const Route = createRootRoute({
|
||||
head: () => siteHead(siteContent),
|
||||
head: () => {
|
||||
const { meta, scripts } = siteHead(siteContent);
|
||||
return {
|
||||
meta: [
|
||||
{ charSet: 'utf-8' },
|
||||
{
|
||||
name: 'viewport',
|
||||
content: 'width=device-width, initial-scale=1.0',
|
||||
},
|
||||
...meta,
|
||||
],
|
||||
links: [
|
||||
{ rel: 'icon', type: 'image/png', href: '/favicon.png' },
|
||||
{ rel: 'apple-touch-icon', href: '/favicon.png' },
|
||||
],
|
||||
scripts,
|
||||
};
|
||||
},
|
||||
shellComponent: RootDocument,
|
||||
component: RootLayout,
|
||||
// Onbekende URL: 404 binnen de shell (FR-09)
|
||||
notFoundComponent: NotFound,
|
||||
|
||||
@@ -2,22 +2,38 @@ import { ChakraProvider } from '@chakra-ui/react';
|
||||
import {
|
||||
createMemoryHistory,
|
||||
createRouter,
|
||||
HeadContent,
|
||||
RouterProvider,
|
||||
rootRouteId,
|
||||
} from '@tanstack/react-router';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { expect } from 'vitest';
|
||||
import ErrorPage from '../components/StatusPage/ErrorPage';
|
||||
import { routeTree } from '../routeTree.gen';
|
||||
import { routerOptions } from '../router';
|
||||
import system from '../theme';
|
||||
|
||||
// De echte app: route tree, router-opties en thema zoals in main.tsx
|
||||
// De root route rendert in de browser het hele document (<html>, <body>). Dat
|
||||
// past niet in de testcontainer: React zou <html lang> op het testdocument
|
||||
// zetten en het thema twee keer wikkelen. Tests krijgen daarom een shell met
|
||||
// alleen de head-tags; verder is het dezelfde route tree (V2, D12).
|
||||
const TestShell = ({ children }: { children: ReactNode }) => (
|
||||
<>
|
||||
<HeadContent />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
||||
// De echte app: route tree en router-opties uit router.tsx, thema zoals in de
|
||||
// shell van __root.tsx
|
||||
export async function renderApp(path: string) {
|
||||
const router = createRouter({
|
||||
routeTree,
|
||||
...routerOptions(),
|
||||
history: createMemoryHistory({ initialEntries: [path] }),
|
||||
scrollRestoration: true,
|
||||
defaultErrorComponent: ErrorPage,
|
||||
});
|
||||
const rootOptions = router.routesById[rootRouteId].options as {
|
||||
shellComponent?: typeof TestShell;
|
||||
};
|
||||
rootOptions.shellComponent = TestShell;
|
||||
await router.load();
|
||||
const result = render(
|
||||
<ChakraProvider value={system}>
|
||||
|
||||
Reference in New Issue
Block a user