mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +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);
|
||||
|
||||
Reference in New Issue
Block a user