Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(geomap): point MapLibre at the worker the bundler emits
Elian Doran77991a61b7c3
diff --git a/apps/client/src/widgets/collections/geomap/Pois.spec.tsx b/apps/client/src/widgets/collections/geomap/Pois.spec.tsxindex 6651afc4ed..d4d4eef393 100644--- a/apps/client/src/widgets/collections/geomap/Pois.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/Pois.spec.tsx@@ -43,7 +43,7 @@ const { FakePopup } = vi.hoisted(() => {return { FakePopup };});-vi.mock("maplibre-gl", () => ({ Popup: FakePopup }));+vi.mock("maplibre-gl", () => ({ Popup: FakePopup, setWorkerUrl: vi.fn() }));/** What the tooltip currently reads, or `null` where none is up. */function tooltipText() {diff --git a/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx b/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsxindex aee8e2580d..d2ec2f4af4 100644--- a/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/Tooltips.spec.tsx@@ -84,7 +84,7 @@ const { FakePopup, PREVIEW_WIDTH } = vi.hoisted(() => {return { FakePopup, PREVIEW_WIDTH, PREVIEW_HEIGHT };});-vi.mock("maplibre-gl", () => ({ Popup: FakePopup }));+vi.mock("maplibre-gl", () => ({ Popup: FakePopup, setWorkerUrl: vi.fn() }));/*** A map that delegates events — per layer or map-wide — and answers the questions the placementdiff --git a/apps/client/src/widgets/collections/geomap/map.init.spec.tsx b/apps/client/src/widgets/collections/geomap/map.init.spec.tsxindex e2468c85ac..134f09af83 100644--- a/apps/client/src/widgets/collections/geomap/map.init.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/map.init.spec.tsx@@ -28,9 +28,10 @@ function failingMap(): never {const { MapConstructor } = vi.hoisted(() => ({ MapConstructor: vi.fn() }));vi.mock("maplibre-gl", () => ({+ AttributionControl: class {},Map: MapConstructor,ScaleControl: class {},- AttributionControl: class {}+ setWorkerUrl: vi.fn()}));vi.mock("maplibre-gl/dist/maplibre-gl.css", () => ({}));diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsxindex 0dfbedf1af..101a2aea7f 100644--- a/apps/client/src/widgets/collections/geomap/map.tsx+++ b/apps/client/src/widgets/collections/geomap/map.tsx@@ -1,6 +1,7 @@import "maplibre-gl/dist/maplibre-gl.css";-import { AttributionControl, type ErrorEvent as MapErrorEvent, Map as MapLibreGLMap, MapMouseEvent, type Point, type RequestTransformFunction, ScaleControl, type StyleSpecification, type TransformStyleFunction } from "maplibre-gl";+import { AttributionControl, type ErrorEvent as MapErrorEvent, Map as MapLibreGLMap, MapMouseEvent, type Point, type RequestTransformFunction, ScaleControl, setWorkerUrl, type StyleSpecification, type TransformStyleFunction } from "maplibre-gl";+import maplibreWorkerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url";import { ComponentChildren, createContext, RefObject } from "preact";import { useEffect, useImperativeHandle, useRef, useState } from "preact/hooks";@@ -18,6 +19,17 @@ export interface GeoMouseEvent {point: Point;}+/**+ * Where MapLibre finds the worker that parses vector and GeoJSON tiles.+ *+ * MapLibre ships the worker as a sibling file of its own bundle and resolves it against+ * `import.meta.url`, which after bundling names a chunk in `dist/src` that has no such sibling. The+ * request 404s, no worker starts, and every source parsed off the main thread stays empty: a vector+ * basemap draws nothing at all, and the markers and clusters go missing from a raster one. Named+ * here instead so the bundler emits the worker and hands back the URL it was emitted under.+ */+setWorkerUrl(maplibreWorkerUrl);+export const ParentMap = createContext<MapLibreGLMap | null>(null);/** The zoom a map opens at where no view has been saved: far enough out to see the whole world. */