chore(client): take the GL engines out of the entry chunk (#1801)

* refactor(settings): load the GL map preview on demand

MapViewGL and JourneyMapGL are both behind lazy() so a Leaflet-only install
never downloads the GL engines. MapboxPreview imported mapbox-gl and maplibre-gl
statically, which put them back in the entry chunk and cancelled that out.

Wrap it in lazy()/Suspense on both the desktop tab and the mobile screen. The
entry chunk drops from 7987 kB to 5157 kB (2057 kB to 1292 kB gzipped); the
engines now ship as their own chunk, loaded when a GL provider is picked.

The preview no longer resolves synchronously, so the tests that read it right
after switching provider await it now.

* chore(client): drop unused deps, self-host MuseoModerno, add a bundle baseline

@react-pdf/renderer, react-window and @types/react-window have no importers
anywhere: TripPDF builds HTML for the browser print window and JourneyBookPDF
goes through marked. RegisterPage is dead too, /register renders LoginPage.

MuseoModerno was the last font still coming from the Google CDN through a
render-blocking <link>, while main.tsx already self-hosts Poppins and Geist for
exactly the reason stated in the comment there. Same weights, now bundled.

Add rollup-plugin-visualizer behind `npm run build:analyze` so the splitting work
has numbers to argue with, pin build.target instead of inheriting Vite's default,
and bring the workbox size ceiling down from 10 MB to 6 MB — anything above it is
dropped from the precache manifest silently, which only shows up as a broken
offline app.
This commit is contained in:
Maurice
2026-08-06 22:25:12 +02:00
committed by GitHub
parent 06f5bc2c86
commit 2b11990063
12 changed files with 332 additions and 928 deletions
@@ -183,7 +183,8 @@ describe('MapSettingsTab – GL providers', () => {
expect(screen.getByText('Mapbox Access Token')).toBeInTheDocument();
expect(screen.getByText('Map Style')).toBeInTheDocument();
expect(screen.queryByText('Map Template')).not.toBeInTheDocument();
expect(screen.getByTestId('gl-preview')).toHaveAttribute('data-provider', 'mapbox-gl');
// The preview is lazy-loaded, so the first read of it has to await the chunk.
expect(await screen.findByTestId('gl-preview')).toHaveAttribute('data-provider', 'mapbox-gl');
expect(screen.getByDisplayValue(MAPBOX_STANDARD)).toBeInTheDocument();
});
@@ -240,7 +241,7 @@ describe('MapSettingsTab – GL providers', () => {
expect(screen.queryByText('3D Buildings & Terrain')).not.toBeInTheDocument();
expect(screen.getByDisplayValue(OFM_LIBERTY)).toBeInTheDocument();
expect(screen.getByText('Preset or OpenFreeMap style URL. OpenFreeMap styles work without a token.')).toBeInTheDocument();
expect(screen.getByTestId('gl-preview')).toHaveAttribute('data-provider', 'maplibre-gl');
expect(await screen.findByTestId('gl-preview')).toHaveAttribute('data-provider', 'maplibre-gl');
});
it('FE-COMP-MAP-023: switching from MapLibre back to Mapbox drops the OpenFreeMap style', async () => {
@@ -274,7 +275,7 @@ describe('MapSettingsTab – GL providers', () => {
await user.type(screen.getByPlaceholderText('pk.eyJ1Ijoi...'), 'pk.token');
expect(screen.getByTestId('gl-preview')).toHaveAttribute('data-token', 'pk.token');
expect(await screen.findByTestId('gl-preview')).toHaveAttribute('data-token', 'pk.token');
});
it('FE-COMP-MAP-026: the 3D and quality toggles drive the preview', async () => {
@@ -282,6 +283,7 @@ describe('MapSettingsTab – GL providers', () => {
render(<MapSettingsTab />);
await user.click(screen.getByText('Mapbox GL'));
await screen.findByTestId('gl-preview');
const preview = () => screen.getByTestId('gl-preview');
expect(preview()).toHaveAttribute('data-3d', 'true');
expect(preview()).toHaveAttribute('data-quality', 'false');
@@ -1,11 +1,14 @@
import React, { useState, useEffect, useMemo, useRef } from 'react'
import React, { useState, useEffect, useMemo, useRef, lazy, Suspense } from 'react'
import { Map, Save, Layers, Box, ChevronDown, Check, Globe2 } from 'lucide-react'
import { useTranslation } from '../../i18n'
import { useSettingsStore } from '../../store/settingsStore'
import { useToast } from '../shared/Toast'
import CustomSelect from '../shared/CustomSelect'
import { MapView } from '../Map/MapView'
import GlMapPreview from './MapboxPreview'
// The preview is the only place that imports both GL engines eagerly, which put
// them in the entry chunk and cancelled out the lazy split in MapViewAuto. Load
// it on demand so a Leaflet-only install never pays for them.
const GlMapPreview = lazy(() => import('./MapboxPreview'))
import Section from './Section'
import ToggleSwitch from './ToggleSwitch'
import type { Place } from '../../types'
@@ -399,18 +402,20 @@ export default function MapSettingsTab(): React.ReactElement {
<div>
<div style={{ position: 'relative', inset: 0, height: '200px', width: '100%' }}>
{provider !== 'leaflet' ? (
<GlMapPreview
provider={provider}
token={mapboxToken}
style={mapboxStyle}
lat={PREVIEW_CENTER[0]}
lng={PREVIEW_CENTER[1]}
// Zoom in close so the style's character (3D buildings,
// satellite texture, label density) is immediately visible.
zoom={PREVIEW_ZOOM}
enable3d={provider === 'mapbox-gl' && mapbox3d && supports3d}
quality={provider === 'mapbox-gl' && mapboxQuality}
/>
<Suspense fallback={<div className="h-full w-full bg-surface-secondary animate-pulse" />}>
<GlMapPreview
provider={provider}
token={mapboxToken}
style={mapboxStyle}
lat={PREVIEW_CENTER[0]}
lng={PREVIEW_CENTER[1]}
// Zoom in close so the style's character (3D buildings,
// satellite texture, label density) is immediately visible.
zoom={PREVIEW_ZOOM}
enable3d={provider === 'mapbox-gl' && mapbox3d && supports3d}
quality={provider === 'mapbox-gl' && mapboxQuality}
/>
</Suspense>
) : (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
React.createElement(MapView as any, {
+5
View File
@@ -9,6 +9,11 @@ import '@fontsource/poppins/400.css'
import '@fontsource/poppins/500.css'
import '@fontsource/poppins/600.css'
import '@fontsource/poppins/700.css'
// MuseoModerno for the login wordmark — same reasoning, it used to come from the
// Google Fonts CDN via a render-blocking <link> in index.html.
import '@fontsource/museomoderno/400.css'
import '@fontsource/museomoderno/700.css'
import '@fontsource/museomoderno/800.css'
// Geist Sans (self-hosted too) — used only for secondary "subtext" via --font-subtext.
import '@fontsource/geist-sans/400.css'
import '@fontsource/geist-sans/500.css'
@@ -1,10 +1,12 @@
import React, { useEffect, useMemo, useState } from 'react'
import React, { useEffect, useMemo, useState, lazy, Suspense } from 'react'
import { Box, Check, ChevronDown, Globe2, Layers, Map, Save } from 'lucide-react'
import { useTranslation } from '../../../i18n'
import { useSettingsStore } from '../../../store/settingsStore'
import { useToast } from '../../../components/shared/Toast'
import { MapView } from '../../../components/Map/MapView'
import GlMapPreview from '../../../components/Settings/MapboxPreview'
// Lazy for the same reason as the desktop map settings tab: this import is what
// dragged both GL engines into the entry chunk.
const GlMapPreview = lazy(() => import('../../../components/Settings/MapboxPreview'))
import type { Place } from '../../../types'
import {
MAPBOX_DEFAULT_STYLE,
@@ -249,16 +251,18 @@ export default function MSettingsMap() {
<div className="relative mt-3 h-[200px] w-full overflow-hidden rounded-xl">
{provider !== 'leaflet' ? (
<GlMapPreview
provider={provider}
token={mapboxToken}
style={mapboxStyle}
lat={PREVIEW_CENTER[0]}
lng={PREVIEW_CENTER[1]}
zoom={PREVIEW_ZOOM}
enable3d={provider === 'mapbox-gl' && mapbox3d}
quality={provider === 'mapbox-gl' && mapboxQuality}
/>
<Suspense fallback={<div className="h-full w-full bg-m-card animate-pulse" />}>
<GlMapPreview
provider={provider}
token={mapboxToken}
style={mapboxStyle}
lat={PREVIEW_CENTER[0]}
lng={PREVIEW_CENTER[1]}
zoom={PREVIEW_ZOOM}
enable3d={provider === 'mapbox-gl' && mapbox3d}
quality={provider === 'mapbox-gl' && mapboxQuality}
/>
</Suspense>
) : (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
React.createElement(MapView as any, {
-186
View File
@@ -1,186 +0,0 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen, waitFor } from '../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '../../tests/helpers/msw/server';
import { resetAllStores } from '../../tests/helpers/store';
import RegisterPage from './RegisterPage';
const mockNavigate = vi.fn();
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual('react-router-dom');
return { ...actual, useNavigate: () => mockNavigate };
});
const USERNAME_PLACEHOLDER = 'johndoe';
const EMAIL_PLACEHOLDER = 'your@email.com';
const PASSWORD_PLACEHOLDER = 'Min. 6 characters';
const CONFIRM_PASSWORD_PLACEHOLDER = 'Repeat password';
beforeEach(() => {
resetAllStores();
vi.clearAllMocks();
});
describe('RegisterPage', () => {
describe('FE-PAGE-REG-001: Renders registration form with all fields', () => {
it('shows username, email, password, confirm-password inputs and submit button', () => {
render(<RegisterPage />);
expect(screen.getByPlaceholderText(USERNAME_PLACEHOLDER)).toBeInTheDocument();
expect(screen.getByPlaceholderText(EMAIL_PLACEHOLDER)).toBeInTheDocument();
expect(screen.getByPlaceholderText(PASSWORD_PLACEHOLDER)).toBeInTheDocument();
expect(screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /register/i })).toBeInTheDocument();
});
});
describe('FE-PAGE-REG-002: Password mismatch shows error', () => {
it('displays mismatch error without calling API', async () => {
const user = userEvent.setup();
render(<RegisterPage />);
await user.type(screen.getByPlaceholderText(USERNAME_PLACEHOLDER), 'testuser');
await user.type(screen.getByPlaceholderText(EMAIL_PLACEHOLDER), 'test@example.com');
await user.type(screen.getByPlaceholderText(PASSWORD_PLACEHOLDER), 'password1');
await user.type(screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER), 'password2');
await user.click(screen.getByRole('button', { name: /^register$/i }));
await waitFor(() => {
expect(screen.getByText(/do not match/i)).toBeInTheDocument();
});
});
});
describe('FE-PAGE-REG-003: Password too short shows error', () => {
it('displays length error when passwords are the same but too short', async () => {
const user = userEvent.setup();
render(<RegisterPage />);
await user.type(screen.getByPlaceholderText(USERNAME_PLACEHOLDER), 'testuser');
await user.type(screen.getByPlaceholderText(EMAIL_PLACEHOLDER), 'test@example.com');
await user.type(screen.getByPlaceholderText(PASSWORD_PLACEHOLDER), 'abc');
await user.type(screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER), 'abc');
await user.click(screen.getByRole('button', { name: /^register$/i }));
await waitFor(() => {
expect(screen.getByText(/at least 8/i)).toBeInTheDocument();
});
});
});
describe('FE-PAGE-REG-004: Successful registration navigates to /dashboard', () => {
it('calls navigate("/dashboard") after successful registration', async () => {
const user = userEvent.setup();
render(<RegisterPage />);
await user.type(screen.getByPlaceholderText(USERNAME_PLACEHOLDER), 'testuser');
await user.type(screen.getByPlaceholderText(EMAIL_PLACEHOLDER), 'test@example.com');
await user.type(screen.getByPlaceholderText(PASSWORD_PLACEHOLDER), 'password123');
await user.type(screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER), 'password123');
await user.click(screen.getByRole('button', { name: /^register$/i }));
await waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith('/dashboard');
});
});
});
describe('FE-PAGE-REG-005: Loading state during submission', () => {
it('disables submit button and shows loading text while registering', async () => {
server.use(
http.post('/api/auth/register', async () => {
await new Promise(resolve => setTimeout(resolve, 100));
return HttpResponse.json({ user: { id: 1, username: 'newuser' } });
}),
);
const user = userEvent.setup();
render(<RegisterPage />);
await user.type(screen.getByPlaceholderText(USERNAME_PLACEHOLDER), 'testuser');
await user.type(screen.getByPlaceholderText(EMAIL_PLACEHOLDER), 'test@example.com');
await user.type(screen.getByPlaceholderText(PASSWORD_PLACEHOLDER), 'password123');
await user.type(screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER), 'password123');
await user.click(screen.getByRole('button', { name: /^register$/i }));
await waitFor(() => {
const btn = screen.getByRole('button', { name: /registering/i });
expect(btn).toBeDisabled();
});
});
});
describe('FE-PAGE-REG-006: API error displayed', () => {
it('shows error message returned by the API', async () => {
server.use(
http.post('/api/auth/register', () => {
return HttpResponse.json({ error: 'Username already taken' }, { status: 409 });
}),
);
const user = userEvent.setup();
render(<RegisterPage />);
await user.type(screen.getByPlaceholderText(USERNAME_PLACEHOLDER), 'testuser');
await user.type(screen.getByPlaceholderText(EMAIL_PLACEHOLDER), 'test@example.com');
await user.type(screen.getByPlaceholderText(PASSWORD_PLACEHOLDER), 'password123');
await user.type(screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER), 'password123');
await user.click(screen.getByRole('button', { name: /^register$/i }));
await waitFor(() => {
expect(screen.getByText('Username already taken')).toBeInTheDocument();
});
});
});
describe('FE-PAGE-REG-007: Show/hide password toggle', () => {
it('toggles password input type between password and text', async () => {
const user = userEvent.setup();
render(<RegisterPage />);
const passwordInput = screen.getByPlaceholderText(PASSWORD_PLACEHOLDER);
const confirmInput = screen.getByPlaceholderText(CONFIRM_PASSWORD_PLACEHOLDER);
expect(passwordInput).toHaveAttribute('type', 'password');
expect(confirmInput).toHaveAttribute('type', 'password');
// The toggle button is the only button of type "button" (not submit) before form submission
const toggleButton = screen.getByRole('button', { name: '' });
await user.click(toggleButton);
expect(passwordInput).toHaveAttribute('type', 'text');
expect(confirmInput).toHaveAttribute('type', 'text');
await user.click(toggleButton);
expect(passwordInput).toHaveAttribute('type', 'password');
expect(confirmInput).toHaveAttribute('type', 'password');
});
});
describe('FE-PAGE-REG-008: Link to login page is present', () => {
it('renders a Sign In link pointing to /login', () => {
render(<RegisterPage />);
const link = screen.getByRole('link', { name: /sign in/i });
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', '/login');
});
});
describe('FE-PAGE-REG-009: Feature list rendered', () => {
it('renders feature list items in the DOM', () => {
render(<RegisterPage />);
// Features are always in the DOM (hidden via CSS on mobile)
expect(screen.getByText(/Unlimited trip plans/i)).toBeInTheDocument();
expect(screen.getByText(/Interactive map view/i)).toBeInTheDocument();
expect(screen.getByText(/Track reservations/i)).toBeInTheDocument();
});
});
describe('FE-PAGE-REG-010: Required attribute on username input', () => {
it('username input has required attribute', () => {
render(<RegisterPage />);
expect(screen.getByPlaceholderText(USERNAME_PLACEHOLDER)).toBeRequired();
});
});
});
-158
View File
@@ -1,158 +0,0 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { useTranslation } from '../i18n'
import { Map, Eye, EyeOff, Mail, Lock, User } from 'lucide-react'
import { useRegister } from './register/useRegister'
export default function RegisterPage(): React.ReactElement {
const { t } = useTranslation()
// Page = wiring container: form state, validation + register flow live in the hook.
const {
username, setUsername, email, setEmail, password, setPassword,
confirmPassword, setConfirmPassword, showPassword, setShowPassword,
isLoading, error, handleSubmit,
} = useRegister()
return (
<div className="min-h-screen flex">
{/* Left panel */}
<div className="hidden lg:flex lg:w-1/2 bg-slate-900 flex-col justify-center items-center p-12 text-white">
<div className="max-w-sm text-center">
<div className="w-20 h-20 bg-white/10 rounded-2xl flex items-center justify-center mx-auto mb-6">
<Map className="w-10 h-10 text-white" />
</div>
<h1 className="text-4xl font-bold mb-4">{t('register.getStarted')}</h1>
<p className="text-slate-300 text-lg leading-relaxed">
{t('register.subtitle')}
</p>
<div className="mt-10 space-y-3 text-left">
{[
`✓ ${t('register.feature1')}`,
`✓ ${t('register.feature2')}`,
`✓ ${t('register.feature3')}`,
`✓ ${t('register.feature4')}`,
`✓ ${t('register.feature5')}`,
`✓ ${t('register.feature6')}`,
].map(item => (
<p key={item} className="text-slate-200 text-sm">{item}</p>
))}
</div>
</div>
</div>
{/* Right panel */}
<div className="flex-1 flex items-center justify-center p-8 bg-slate-50">
<div className="w-full max-w-md">
<div className="lg:hidden flex items-center gap-2 mb-8 justify-center">
<Map className="w-8 h-8 text-slate-900" />
<span className="text-2xl font-bold text-slate-900">TREK</span>
</div>
<div className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
<h2 className="text-2xl font-bold text-slate-900 mb-1">{t('register.createAccount')}</h2>
<p className="text-slate-500 mb-8">{t('register.startPlanning')}</p>
<form onSubmit={handleSubmit} className="space-y-5">
{error && (
<div className="p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-600">
{error}
</div>
)}
<div>
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('settings.username')}</label>
<div className="relative">
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-slate-400" />
<input
type="text"
value={username}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setUsername(e.target.value)}
required
placeholder="johndoe"
minLength={3}
className="w-full pl-10 pr-4 py-2.5 border border-slate-300 rounded-lg text-slate-900 placeholder-slate-400 focus:ring-2 focus:ring-slate-400 focus:border-transparent transition-[border-color,box-shadow] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)]"
/>
</div>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('common.email')}</label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-slate-400" />
<input
type="email"
value={email}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)}
required
placeholder="your@email.com"
className="w-full pl-10 pr-4 py-2.5 border border-slate-300 rounded-lg text-slate-900 placeholder-slate-400 focus:ring-2 focus:ring-slate-400 focus:border-transparent transition-[border-color,box-shadow] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)]"
/>
</div>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('common.password')}</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-slate-400" />
<input
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setPassword(e.target.value)}
required
placeholder={t('register.minChars')}
className="w-full pl-10 pr-12 py-2.5 border border-slate-300 rounded-lg text-slate-900 placeholder-slate-400 focus:ring-2 focus:ring-slate-400 focus:border-transparent transition-[border-color,box-shadow] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)]"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600"
>
{showPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
</button>
</div>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('register.confirmPassword')}</label>
<div className="relative">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-slate-400" />
<input
type={showPassword ? 'text' : 'password'}
value={confirmPassword}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setConfirmPassword(e.target.value)}
required
placeholder={t('register.repeatPassword')}
className="w-full pl-10 pr-4 py-2.5 border border-slate-300 rounded-lg text-slate-900 placeholder-slate-400 focus:ring-2 focus:ring-slate-400 focus:border-transparent transition-[border-color,box-shadow] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)]"
/>
</div>
</div>
<button
type="submit"
disabled={isLoading}
className="w-full py-2.5 px-4 bg-slate-900 hover:bg-slate-700 disabled:bg-slate-400 text-white font-medium rounded-lg transition-colors flex items-center justify-center gap-2"
>
{isLoading ? (
<>
<div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
{t('register.registering')}
</>
) : t('register.register')}
</button>
</form>
<div className="mt-6 text-center">
<p className="text-sm text-slate-500">
{t('register.hasAccount')}{' '}
<Link to="/login" className="text-slate-900 hover:text-slate-700 font-medium">
{t('register.signIn')}
</Link>
</p>
</div>
</div>
</div>
</div>
</div>
)
}
-54
View File
@@ -1,54 +0,0 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useAuthStore } from '../../store/authStore'
import { useTranslation } from '../../i18n'
/**
* Register data hook — owns the form state, the client-side validation and the
* register → redirect flow. RegisterPage is a pure wiring container. Behaviour
* is identical to the previous in-component logic.
*/
export function useRegister() {
const { t } = useTranslation()
const { register } = useAuthStore()
const navigate = useNavigate()
const [username, setUsername] = useState<string>('')
const [email, setEmail] = useState<string>('')
const [password, setPassword] = useState<string>('')
const [confirmPassword, setConfirmPassword] = useState<string>('')
const [showPassword, setShowPassword] = useState<boolean>(false)
const [isLoading, setIsLoading] = useState<boolean>(false)
const [error, setError] = useState<string>('')
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>): Promise<void> => {
e.preventDefault()
setError('')
if (password !== confirmPassword) {
setError(t('register.passwordMismatch'))
return
}
if (password.length < 8) {
setError(t('register.passwordTooShort'))
return
}
setIsLoading(true)
try {
await register(username, email, password)
navigate('/dashboard')
} catch (err: unknown) {
setError(err instanceof Error ? err.message : t('register.failed'))
} finally {
setIsLoading(false)
}
}
return {
username, setUsername, email, setEmail, password, setPassword,
confirmPassword, setConfirmPassword, showPassword, setShowPassword,
isLoading, error, handleSubmit,
}
}