fix(offline): the osm-de and stadia prefetch was CSP-blocked and the opening view stayed grey (#2180)

connect-src never listed tile.openstreetmap.de or tiles.stadiamaps.com, so every prefetch fetch was refused before the service worker saw it, while the swallowed error still counted as a cached tile. Both hosts are allowed now and only reached tiles count. The prefetch rectangle is also widened to the screen the fitBounds view fills, on the raster and the vector path alike; the places extent alone left grey bands beside a north-south trip.
This commit is contained in:
Maurice
2026-09-02 19:00:35 +02:00
committed by Maurice
parent fc6843528c
commit 2ab2dcc3dc
6 changed files with 215 additions and 26 deletions
@@ -156,6 +156,22 @@ describe('prefetchVectorForPlaces', () => {
expect([...zooms].sort((a, b) => a - b)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);
});
it('FE-SYNC-GLPF-014: reaches as far as the screen the map opens on, not just the places extent', async () => {
// Berlin + Munich: fitBounds is height-limited, so the opening view shows far
// more longitude than the places extent, and that band was grey offline (#2180).
await prefetchVectorForPlaces([
buildPlace({ lat: 52.52, lng: 13.405 }),
buildPlace({ lat: 48.14, lng: 11.58 }),
], STYLE_URL);
const xs = [...cache.store.keys()]
.filter(u => u.endsWith('.pbf') && u.includes('/planet/'))
.map(u => u.split('/planet/')[1]!.split('/'))
.filter(parts => Number(parts[1]) === 7)
.map(parts => Number(parts[2]));
expect((Math.max(...xs) - Math.min(...xs) + 1) * 256).toBeGreaterThanOrEqual(window.innerWidth);
});
it('FE-SYNC-GLPF-008: does nothing offline', async () => {
Object.defineProperty(navigator, 'onLine', { value: false, writable: true, configurable: true });
await expect(prefetchVectorForPlaces(places, STYLE_URL)).resolves.toEqual({ tiles: 0, template: null });