Skip to content

Commit c3c02a2

Browse files
authored
fix(vector): forward offline spatial-extension path to the Add Vector panel (#446)
* fix(vector): forward offline spatial-extension path to the Add Vector panel The Add Vector panel's maplibre-gl-vector control runs its own DuckDB-WASM engine, which installs the spatial extension from a remote repository. In sandboxed or firewalled environments that install hangs, leaving the panel stuck on "Loading DuckDB-WASM..." (#445). Forward VITE_DUCKDB_SPATIAL_EXTENSION_PATH (the same variable GeoLibre's own DuckDB loader honours) to the control via its new spatialExtensionPath option, so it loads a local extension instead of the remote INSTALL. The helper reads the runtime env through @geolibre/core so the plugin package does not depend on the desktop app. Requires maplibre-gl-vector with the spatialExtensionPath option (opengeos/maplibre-gl-vector#17). * chore(deps): bump maplibre-gl-vector to ^0.4.0 0.4.0 publishes the spatialExtensionPath option this branch consumes (opengeos/maplibre-gl-vector#17), so the dependency range must include it. Bumps both workspaces (apps/geolibre-desktop, packages/plugins) and the lockfile to the published 0.4.0. * Address Claude review feedback - Centralize getSpatialExtensionPath in @geolibre/core (runtime-env.ts) and export it, replacing the line-for-line duplicate that lived in the plugin. Both consumers (desktop duckdb loader via the spatial-extension-config re-export, and the maplibre-vector plugin) now share one implementation, so the VITE_DUCKDB_SPATIAL_EXTENSION_PATH logic cannot silently diverge. - Drop the now-redundant tests/vector-spatial-extension-path.test.ts; the same logic is covered by tests/spatial-extension-config.test.ts. * Address Claude review feedback - Simplify getSpatialExtensionPath: single trim via optional chaining (`value?.trim() || undefined`) instead of trimming twice.
1 parent 0f21498 commit c3c02a2

7 files changed

Lines changed: 39 additions & 18 deletions

File tree

apps/geolibre-desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"maplibre-gl-streetview": "^0.6.0",
7575
"maplibre-gl-swipe": "^0.7.1",
7676
"maplibre-gl-time-slider": "^1.0.3",
77-
"maplibre-gl-vector": "^0.3.0",
77+
"maplibre-gl-vector": "^0.4.0",
7878
"openai": "^6.39.0",
7979
"qrcode.react": "^4.2.0",
8080
"react": "^19.2.7",
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { getRuntimeEnvironment } from "@geolibre/core";
2-
3-
export function getSpatialExtensionPath(
4-
env?: Record<string, string | undefined>,
5-
): string | undefined {
6-
const runtimeEnv = env ?? getRuntimeEnvironment();
7-
const value = runtimeEnv.VITE_DUCKDB_SPATIAL_EXTENSION_PATH;
8-
return value && value.trim() ? value.trim() : undefined;
9-
}
1+
// The shared implementation lives in @geolibre/core so the desktop loader and
2+
// the maplibre-gl-vector plugin resolve VITE_DUCKDB_SPATIAL_EXTENSION_PATH the
3+
// same way. Re-exported here to keep this module path stable for existing
4+
// importers (sql-workspace, duckdb-vector-loader, ...).
5+
export { getSpatialExtensionPath } from "@geolibre/core";

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ export {
7171
type GeocodeRequest,
7272
type ReverseGeocodeDisplay,
7373
} from "./geocoding";
74-
export { getRuntimeEnvironment } from "./runtime-env";
74+
export { getRuntimeEnvironment, getSpatialExtensionPath } from "./runtime-env";

packages/core/src/runtime-env.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,25 @@ export function getRuntimeEnvironment(): Record<string, string | undefined> {
2727
...(window.__GEOLIBRE_RUNTIME_ENV__ ?? {}),
2828
};
2929
}
30+
31+
/**
32+
* Resolves a local DuckDB spatial extension path from the runtime environment.
33+
*
34+
* When `VITE_DUCKDB_SPATIAL_EXTENSION_PATH` is set, DuckDB consumers (the
35+
* desktop app's own loader and the Add Vector panel's maplibre-gl-vector
36+
* control) load the spatial extension from this path with `LOAD '<path>'`
37+
* instead of installing it from the remote repository, which hangs in
38+
* sandboxed or firewalled environments. Lives in `@geolibre/core` so every
39+
* consumer shares one implementation.
40+
*
41+
* @param env - Environment record (defaults to the runtime environment);
42+
* injectable for testing.
43+
* @returns The trimmed extension path, or undefined when unset.
44+
*/
45+
export function getSpatialExtensionPath(
46+
env?: Record<string, string | undefined>,
47+
): string | undefined {
48+
const runtimeEnv = env ?? getRuntimeEnvironment();
49+
const trimmed = runtimeEnv.VITE_DUCKDB_SPATIAL_EXTENSION_PATH?.trim();
50+
return trimmed || undefined;
51+
}

packages/plugins/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"maplibre-gl-streetview": "^0.6.0",
4949
"maplibre-gl-swipe": "^0.7.1",
5050
"maplibre-gl-time-slider": "^1.0.3",
51-
"maplibre-gl-vector": "^0.3.0",
51+
"maplibre-gl-vector": "^0.4.0",
5252
"proj4": "^2.20.9",
5353
"shpjs": "^6.2.0",
5454
"three": "^0.184.0"

packages/plugins/src/plugins/maplibre-vector.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useAppStore } from "@geolibre/core";
1+
import { getSpatialExtensionPath, useAppStore } from "@geolibre/core";
22
import type {
33
VectorControl,
44
VectorControlEventHandler,
@@ -301,6 +301,9 @@ function createVectorControl(
301301
panelWidth: 380,
302302
title: "Add Vector Layer",
303303
urlPlaceholder: DEFAULT_VECTOR_URL,
304+
// Skip the remote spatial-extension install in offline/sandboxed
305+
// environments when a local extension path is configured.
306+
spatialExtensionPath: getSpatialExtensionPath(),
304307
});
305308

306309
for (const event of ["layeradded", "layerremoved", "layerupdated"] as const) {

0 commit comments

Comments
 (0)