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, {