mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
fix(ci): repair map fixtures and keep renderer dependencies layered
Use the engine write lock for map defaults and clean the metadata-free test snapshot with Kysely. Model the Leaflet bridge option, keep the renderer failure state below the settings store, and make the tile tests independent of the transpiler quote style.
This commit is contained in:
@@ -264,12 +264,14 @@ export function VectorBasemap({ style, hideLabels = false }: { style: string; hi
|
||||
// The style is read through a ref, never from the dependency list: a style
|
||||
// change must retile in place rather than tear the layer down, the same
|
||||
// reason the raster maps keep their template out of the build effect (#2097).
|
||||
const layer = maplibreGL({
|
||||
const options = {
|
||||
style: offlineStyle(styleRef.current),
|
||||
interactive: false,
|
||||
attributionControl: false,
|
||||
// The Leaflet bridge reads this option. Its published type lists only GL options.
|
||||
padding: mapDeviceTier() === 'full' ? 0.25 : 0.1,
|
||||
})
|
||||
} satisfies Parameters<typeof maplibreGL>[0] & { padding: number }
|
||||
const layer = maplibreGL(options)
|
||||
if (!attachGlLayer(map, layer, styleRef.current)) {
|
||||
setGlUsable(false)
|
||||
return
|
||||
|
||||
@@ -48,7 +48,7 @@ export function preloadTripMapRenderer(provider: string | undefined, token: stri
|
||||
const engine = pickGlRenderer(provider, token)
|
||||
if (!engine) return
|
||||
const view = engine === 'maplibre-gl' ? MapViewGLMaplibre : MapViewGLMapbox
|
||||
void view.preload().catch(() => { /* The map boundary handles this if the user opens a map. */ })
|
||||
void view.preload().catch((error: unknown) => console.debug('[map] renderer preload failed', error))
|
||||
}
|
||||
|
||||
export const JourneyMapGLMapbox = lazyWithRetry(async () => {
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
import { offlineStyle } from '../../native/offlineTiles';
|
||||
import { hasWebGL, reportWebGLFailure, subscribeWebGL, webGLFailures } from '../../utils/webgl';
|
||||
import {
|
||||
hasGlEngineFailure,
|
||||
hasWebGL,
|
||||
reportGlEngineFailure,
|
||||
reportWebGLFailure,
|
||||
subscribeWebGL,
|
||||
webGLFailures,
|
||||
} from '../../utils/webgl';
|
||||
import { isGlRasterStyle, type GlStyle } from './glBasemap';
|
||||
import { rememberMapLibreBasemap } from './glBasemapSwap';
|
||||
import type { GlMapProvider } from './glProviders';
|
||||
import { hasGlEngineFailure, reportGlEngineFailure, subscribeGlEngineFailure, watchGlEngine } from './glWatchdog';
|
||||
import { watchGlEngine } from './glWatchdog';
|
||||
import { watchRasterHealth } from './rasterHealth';
|
||||
|
||||
/*
|
||||
@@ -50,7 +57,7 @@ export function useGlRenderer(
|
||||
|
||||
export function useGlEngineFailed(provider: GlMapProvider | null): boolean {
|
||||
const snapshot = () => provider !== null && hasGlEngineFailure(provider);
|
||||
return useSyncExternalStore(subscribeGlEngineFailure, snapshot, snapshot);
|
||||
return useSyncExternalStore(subscribeWebGL, snapshot, snapshot);
|
||||
}
|
||||
|
||||
/** Whether 3D (the GL terrain map) can run here, kept current the same way. */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { clearGlEngineFailure, hasGlEngineFailure, watchGlEngine } from './glWatchdog';
|
||||
import { clearGlEngineFailure, hasGlEngineFailure } from '../../utils/webgl';
|
||||
import { watchGlEngine } from './glWatchdog';
|
||||
|
||||
function fixture() {
|
||||
const canvas = document.createElement('canvas');
|
||||
|
||||
@@ -1,50 +1,11 @@
|
||||
import { OPENFREEMAP_HOST } from '@trek/shared';
|
||||
|
||||
import { reportGlEngineFailure } from '../../utils/webgl';
|
||||
import type { GlMapProvider } from './glProviders';
|
||||
|
||||
const RESTORE_GRACE_MS = 3000;
|
||||
const REPEATED_LOSS_MS = 60_000;
|
||||
|
||||
const sessionKey = (provider: GlMapProvider) => `glBlank:${provider}`;
|
||||
const failures = new Set<GlMapProvider>();
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
export function hasGlEngineFailure(provider: GlMapProvider): boolean {
|
||||
if (failures.has(provider)) return true;
|
||||
try {
|
||||
return globalThis.sessionStorage?.getItem(sessionKey(provider)) === '1';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function subscribeGlEngineFailure(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
|
||||
export function reportGlEngineFailure(provider: GlMapProvider): void {
|
||||
if (hasGlEngineFailure(provider)) return;
|
||||
failures.add(provider);
|
||||
try {
|
||||
globalThis.sessionStorage?.setItem(sessionKey(provider), '1');
|
||||
} catch {
|
||||
// A browser that blocks storage still falls back on this page.
|
||||
}
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
export function clearGlEngineFailure(provider: GlMapProvider): void {
|
||||
if (!hasGlEngineFailure(provider)) return;
|
||||
failures.delete(provider);
|
||||
try {
|
||||
globalThis.sessionStorage?.removeItem(sessionKey(provider));
|
||||
} catch {
|
||||
// The in-memory flag has already been cleared.
|
||||
}
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
interface WatchedGlMap {
|
||||
getCanvas(): HTMLCanvasElement;
|
||||
getContainer(): HTMLElement;
|
||||
|
||||
@@ -3,7 +3,7 @@ import L from 'leaflet';
|
||||
|
||||
import { templateHost } from '../../utils/tileUrl';
|
||||
|
||||
export function rasterUpdatesWhenIdle(template: string, mobile = L.Browser.mobile): boolean {
|
||||
export function rasterUpdatesWhenIdle(template: string, mobile = L.Browser?.mobile ?? true): boolean {
|
||||
const host = templateHost(template);
|
||||
return mobile || (host !== 'tile.openstreetmap.de' && host !== OPENFREEMAP_HOST);
|
||||
}
|
||||
|
||||
@@ -94,10 +94,15 @@ export function useEffectiveMapEngine(tileUrl: string | undefined): EffectiveMap
|
||||
pill = { kind: 'classic' };
|
||||
}
|
||||
|
||||
if (glFallback) {
|
||||
return maplibreFailed
|
||||
? { engine: null, tileUrlOverride: offlineStyle, pill }
|
||||
: { engine: 'maplibre-gl', styleOverride: offlineStyle, pill };
|
||||
}
|
||||
return {
|
||||
engine: glFallback ? (maplibreFailed ? null : 'maplibre-gl') : drawn.engine,
|
||||
styleOverride: glFallback && !maplibreFailed ? offlineStyle : drawn.style,
|
||||
tileUrlOverride: leafletFallback || (glFallback && maplibreFailed) ? offlineStyle : undefined,
|
||||
engine: drawn.engine,
|
||||
styleOverride: drawn.style,
|
||||
tileUrlOverride: leafletFallback ? offlineStyle : undefined,
|
||||
pill,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, type RefObject } from 'react';
|
||||
import { useEffect, useLayoutEffect, useRef, type RefObject } from 'react';
|
||||
|
||||
import { useSettingsStore } from '../../store/settingsStore';
|
||||
import type { GlStyle } from './glBasemap';
|
||||
@@ -16,7 +16,9 @@ export function useGlStyle(provider: GlMapProvider, override: GlStyle | undefine
|
||||
const maplibreStyle = useSettingsStore((s) => s.settings.maplibre_style || '');
|
||||
const style = override ?? styleForActiveProvider(provider, mapboxStyle, maplibreStyle);
|
||||
const latestStyle = useRef(style);
|
||||
latestStyle.current = style;
|
||||
useLayoutEffect(() => {
|
||||
latestStyle.current = style;
|
||||
}, [style]);
|
||||
const canSwap = provider === 'maplibre-gl' && preservesMapLibreLayers(style);
|
||||
useEffect(() => {
|
||||
if (canSwap) swapMapLibreBasemap(map.current, style);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { normalizeTileUrl, stripTileApiKey } from '../utils/tileUrl'
|
||||
import { clearTileCache } from '../sync/tilePrefetcher'
|
||||
import { cacheAccountSettings, cacheAccountSettingsPatch, cachedAccountSettings } from '../db/cacheAccountSettings'
|
||||
import { rememberStartDestination, DEFAULT_START_PAGE, DEFAULT_START_TRIP_TAB } from '../utils/startDestination'
|
||||
import { clearGlEngineFailure } from '../components/Map/glWatchdog'
|
||||
import { clearGlEngineFailure } from '../utils/webgl'
|
||||
|
||||
function retrySelectedEngine(previous: Settings['map_provider'], next: Settings[keyof Settings]) {
|
||||
if (previous !== next && (next === 'mapbox-gl' || next === 'maplibre-gl')) clearGlEngineFailure(next)
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('isGlRasterTileRequest', () => {
|
||||
});
|
||||
|
||||
it('FE-SYNC-GLTILECACHE-005: every host in the inline list is one the CSP lets a GL map fetch', () => {
|
||||
const inline = [...isGlRasterTileRequest.toString().matchAll(/'([^']+\.[a-z]+)'/g)].map((m) => m[1]);
|
||||
const inline = [...isGlRasterTileRequest.toString().matchAll(/(['"])([^'"]+\.[a-z]+)\1/g)].map((m) => m[2]);
|
||||
expect(inline.length).toBeGreaterThan(0);
|
||||
for (const host of inline) expect(RASTER_TILE_HOSTS, host).toContain(host);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { Settings } from '../types'
|
||||
|
||||
/**
|
||||
* Whether this browser will hand a GL map a WebGL2 context. MapLibre 6 and
|
||||
* Mapbox GL 3 both ask for webgl2 and nothing else.
|
||||
@@ -31,6 +33,40 @@ export function hasWebGL(): boolean {
|
||||
|
||||
const listeners = new Set<() => void>()
|
||||
let failures = 0
|
||||
type GlEngine = Exclude<NonNullable<Settings['map_provider']>, 'leaflet'>
|
||||
const engineFailures = new Set<GlEngine>()
|
||||
const engineKey = (engine: GlEngine) => `glBlank:${engine}`
|
||||
|
||||
export function hasGlEngineFailure(engine: GlEngine): boolean {
|
||||
if (engineFailures.has(engine)) return true
|
||||
try {
|
||||
return globalThis.sessionStorage?.getItem(engineKey(engine)) === '1'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function reportGlEngineFailure(engine: GlEngine): void {
|
||||
if (hasGlEngineFailure(engine)) return
|
||||
engineFailures.add(engine)
|
||||
try {
|
||||
globalThis.sessionStorage?.setItem(engineKey(engine), '1')
|
||||
} catch {
|
||||
// The page still remembers the failure in memory.
|
||||
}
|
||||
for (const listener of listeners) listener()
|
||||
}
|
||||
|
||||
export function clearGlEngineFailure(engine: GlEngine): void {
|
||||
if (!hasGlEngineFailure(engine)) return
|
||||
engineFailures.delete(engine)
|
||||
try {
|
||||
globalThis.sessionStorage?.removeItem(engineKey(engine))
|
||||
} catch {
|
||||
// The page's in-memory flag has already been cleared.
|
||||
}
|
||||
for (const listener of listeners) listener()
|
||||
}
|
||||
|
||||
/**
|
||||
* A GL map that failed to build although the probe said yes: a GPU that offers
|
||||
|
||||
Reference in New Issue
Block a user