fix(ci): use the bound database for map defaults and retry preloads

Write both defaults in one guarded statement so a SQLite source imported by the Postgres suite needs no Postgres lock. Release a failed speculative chunk promise so opening the map can retry it.
This commit is contained in:
Maurice
2026-11-30 16:45:35 +01:00
parent 54c54d5e65
commit dbf011f026
4 changed files with 50 additions and 30 deletions
+1 -1
View File
@@ -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((error: unknown) => console.debug('[map] renderer preload failed', error))
void view.preload()
}
export const JourneyMapGLMapbox = lazyWithRetry(async () => {
+11 -3
View File
@@ -46,14 +46,22 @@ describe('lazyWithRetry', () => {
it('shares the preloaded promise with the lazy component', async () => {
const load = vi.fn(async () => ({ default: () => <div>Map view</div> }))
const Page = lazyWithRetry(load)
const pending = Page.preload()
expect(Page.preload()).toBe(pending)
await pending
await Promise.all([Page.preload(), Page.preload()])
render(<Suspense><Page /></Suspense>)
expect(await screen.findByText('Map view')).toBeInTheDocument()
expect(load).toHaveBeenCalledTimes(1)
})
it('lets navigation retry after a speculative preload fails', async () => {
const load = vi.fn(async () => ({ default: () => <div>Loaded after navigation</div> }))
load.mockRejectedValueOnce(new Error('preload was interrupted'))
const Page = lazyWithRetry(load)
await Page.preload()
render(<Suspense><Page /></Suspense>)
expect(await screen.findByText('Loaded after navigation')).toBeInTheDocument()
expect(load).toHaveBeenCalledTimes(2)
})
it('FE-UTIL-LAZYRETRY-006: renders the default export once the chunk arrives', async () => {
const Page = lazyWithRetry(async () => ({ default: () => <div>Atlas</div> }))
render(
+11 -3
View File
@@ -46,9 +46,9 @@ export function retryUrlFor(error: unknown): string | null {
export function lazyWithRetry<T extends ComponentType<any>>(
load: () => Promise<{ default: T }>
): LazyExoticComponent<T> & { preload: () => Promise<{ default: T }> } {
): LazyExoticComponent<T> & { preload: () => Promise<void> } {
let pending: Promise<{ default: T }> | undefined;
const preload = () => (pending ??= load()
const start = () => (pending ??= load()
.catch((error: unknown) => {
const url = retryUrlFor(error);
// Rethrown on purpose: React.lazy hands the rejection to the nearest
@@ -65,5 +65,13 @@ export function lazyWithRetry<T extends ComponentType<any>>(
clearChunkReloadMarker();
return module;
}));
return Object.assign(lazy(preload), { preload });
const preload = async () => {
try {
await start();
} catch {
// A failed speculative load leaves the actual navigation free to try again.
pending = undefined;
}
};
return Object.assign(lazy(start), { preload });
}