Repository navigation
fix(maplibre): insert interleaved layer groups once sources load - #10734
Conversation
resolveMapLibreLayerGroups returns early until map.isStyleLoaded(), which in MapLibre also waits for every source's tiles and images. The overlay only retried on `styledata`, and on first load those events all fire while tiles are still loading. Layers with `beforeId` were then never added to the style and were drawn on top of the map instead. Also retry on `sourcedata`. Fixes visgl#10733 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
[Medium impact] The PR appears safe to merge. SummaryFixes deferred interleaved layer placement in
The earlier listener-lifetime finding is addressed. No new actionable issues were found. Tests were not run.
|
> [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Closes #1262 Upgrades to deck.gl 9.4 (the last v9 release), luma.gl 9.4, and deck.gl-raster 0.8. deck.gl-raster 0.8 requires deck.gl 9.4. ## Changes - **deck.gl and luma.gl:** `@deck.gl/*` → ^9.4.0 and `@luma.gl/*` → ^9.4.2. Both are updated in `package.json` and in the `overrides` in `pnpm-workspace.yaml`. Those overrides keep a single copy of each package, and they had held the lockfile at 9.3 even after `package.json` was bumped. - **deck.gl-raster family:** `@developmentseed/affine`, `deck.gl-raster`, `morecantile` and `raster-reproject` → ^0.8.1 together. This removes the duplicate `@developmentseed/affine` 0.6.1 and 0.7.0 copies that `main` bundles today. It brings in deck.gl-raster's fixes: - center-first tile loading, now handled by deck.gl 9.4 itself; - lighting turned off for raster layers; - `isLoaded` returning false while metadata loads; - tile traversal latitudes clamped to [-90, 90]; - COG open failures reported through `onError`. - **Undeclared dependencies:** `@deck.gl/aggregation-layers`, `@deck.gl/geo-layers`, `@deck.gl/widgets` and `@luma.gl/core` are now declared. They were imported in `src/`, or required as peers, but only installed because pnpm installs missing peers automatically. The stale `aggregation-layers` 9.3.1 peer was what caused an "unmet peer" warning. - **loaders.gl:** the twelve loaders.gl packages that deck.gl and luma.gl depend on directly are overridden to ~4.4.5. - `@luma.gl/gltf` 9.4 requires loaders.gl ~4.4.5, while deck.gl 9.4 accepts ^4.4.3. - loaders.gl packages pin exact versions of each other. - Without the overrides, a fresh resolution mixes 4.4.5 and 4.5.x. An esbuild metafile showed that bundles seven loaders.gl packages twice. - **dependabot:** `@developmentseed/*` is grouped with deck.gl, so the family moves together. ### Not switching to `@deck.gl/maplibre` yet 9.4 adds `@deck.gl/maplibre` as the MapLibre replacement for `@deck.gl/mapbox`. But in 9.4.0 it draws interleaved layers that set `beforeId` above every MapLibre layer on first page load (visgl/deck.gl#10733). That would break lonboard's `before_id`, so this PR stays on `@deck.gl/mapbox` ^9.4.0. deck.gl-raster made the same call; see developmentseed/deck.gl-raster#661. The fix, visgl/deck.gl#10734, is open. The switch from `MapboxOverlay` to `MapLibreOverlay` in `src/renderers/overlay.tsx` can happen once a release includes it; that's tracked in #1273. ## Verification **Picking.** deck.gl 9.4 drops the auto-generated `instancePickingColors` attribute. Nothing in lonboard reads it, but the existing UI tests never actually asserted that picking works. New `tests/ui/test_picking.py` clicks a feature and checks that Python receives the right `selected_index`, for scatterplot, path, polygon and solid polygon layers. It passes on `main` (deck.gl 9.3) and on this branch. **Static HTML exports.** 15 exports were checked in headless Chromium on both `main` and this branch: five layer types (scatterplot, path, polygon, text, H3) in each of the `overlaid`, `interleaved` and `reverse-controlled` modes. - Hover tooltips appear in every case. - The controls render the same way on both versions. - No console errors. **Raster.** A local tiled GeoTIFF rendered through `RasterLayer.from_geotiff` and deck.gl-raster 0.8 displays correctly. **Replacing a map.** Swapping one map for another in the same output reuses the MapLibre instance (`reuseMaps`). It renders correctly in both `overlaid` and `interleaved` modes, with no "WebGL context already attached" error. That's the problem deck.gl-raster#668 hit under React StrictMode. **Checks:** - `pnpm install --frozen-lockfile`: clean, with no peer-dependency warnings. - `biome check`: clean. - `tsc --noEmit`: the same 8 errors as `main`, with identical messages. - `pytest`: 226 passed, 1 skipped. ## Things to know - **Bundle size:** the bundle grows from 3.46 MB to 3.76 MB (+297 KB, about 8.6%). Most of that is deck.gl 9.4's WebGPU code, which is now included by default. deck.gl offers a `visgl:webgl-only` export condition to drop it, but it has no effect here, because `build.mjs` aliases each `@deck.gl/*` package to a directory path, and export conditions only apply to bare package names. Using it would mean pointing the aliases at the `dist.webgl-only` builds; that's left for a follow-up. - **New console warnings:** luma.gl 9.4.x logs `WebGL uniform block reflection failed for "gouraudMaterialUniforms"` / `"lightingUniforms"` for lit layers such as polygons. Rendering is correct. This is visgl/luma.gl#3187, fixed on luma.gl `master` in visgl/luma.gl#3190 but not backported to the 9.4 branch (9.4.1 and 9.4.2 don't include it). - **Beta:** this is a good point to cut `0.17.0-beta.2`. 🤖 Written by [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
Arm the sourcedata listener only when resolving layer groups is deferred because the style or its sources are still loading, and detach it once the groups are resolved. This avoids reconciling on every tile and GeoJSON update, and also applies layer changes made via setProps while sources reload, including removing groups that are no longer used.
# Conflicts: # test/modules/maplibre/overlay.spec.ts
chrisgervang
left a comment
There was a problem hiding this comment.
@kylebarron I pushed a follow-up on top of your fix to address the Greptile note about sourcedata reconciling on every tile load.
While doing that, I found that isStyleLoaded() is also false while tiles load and added in a fix. It seemed like it could be an issue while panning and something sets a new beforeId.
Could you retest against your original issue? If it looks good on your end, I’ll merge.
|
Thanks @chrisgervang! I had claude take a look at it and it sounds like this PR is effective. I added the before/after screenshots below Note This comment was written by Claude (Claude Code), not by @kylebarron. Retested against #10733 with the original repro,
Your follow-up also works in the app:
Before / after, MapLibre 6.16.0:
Looks good to merge from my side. Could it also be backported to 🤖 Written by Claude Code |
|
And let me know if there's any other feedback I can provide / ask claude to research here |
|
As an outside observer, it feels like deck.gl would benefit from adopting a merge queue so that you don't have to keep merging main back into branches manually and seeing when CI finishes. |
Oh, thanks for the tip - I hadn't heard merge queue was added to github! I only used it on phab.. we'll look into it. |
) * fix(maplibre): insert interleaved layer groups once sources load resolveMapLibreLayerGroups returns early until map.isStyleLoaded(), which in MapLibre also waits for every source's tiles and images. The overlay only retried on `styledata`, and on first load those events all fire while tiles are still loading. Layers with `beforeId` were then never added to the style and were drawn on top of the map instead. Also retry on `sourcedata`. Fixes #10733 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(maplibre): only listen for sourcedata while layer groups are pending Arm the sourcedata listener only when resolving layer groups is deferred because the style or its sources are still loading, and detach it once the groups are resolved. This avoids reconciling on every tile and GeoJSON update, and also applies layer changes made via setProps while sources reload, including removing groups that are no longer used. --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Chris Gervang <[email protected]> Co-authored-by: Chris Gervang <[email protected]> (cherry picked from commit b7a7a33)
> [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Bumps: - `@deck.gl/*` 9.4.0 → [9.4.1](https://github.com/visgl/deck.gl/releases/tag/v9.4.1) - `@developmentseed/{deck.gl-raster,affine,morecantile,raster-reproject}` 0.8.1 → [0.9.0](https://github.com/developmentseed/deck.gl-raster/releases/tag/v0.9.0) → [0.10.0](https://github.com/developmentseed/deck.gl-raster/releases/tag/v0.10.0) The deck.gl overrides in `pnpm-workspace.yaml` go to `^9.4.1` too. Without that, pnpm keeps every overridden deck.gl package at 9.4.0 and only `@deck.gl/react` moves. deck.gl-raster 0.10 now depends on `@developmentseed/range-reader`, so I added it to the commented-out local-checkout overrides. The breaking changes in deck.gl-raster 0.9 and 0.10 are in `deck.gl-geotiff`, `deck.gl-zarr` and `geotiff`, which Lonboard doesn't use. Lonboard only imports `RasterTileLayer`, `TileMatrixSetAdaptor` and `MinimalTileData`, and needs no code changes. Upstream fixes relevant to Lonboard: - deck.gl-raster: tile textures are destroyed when a raster layer is removed (developmentseed/deck.gl-raster#728), and a WebGL vertex array no longer leaks per tile (developmentseed/deck.gl-raster#786). - deck.gl-raster: missing TileMatrixSet bounds are inferred and `extent` is honored (developmentseed/deck.gl-raster#684). The `TMSBoundingBox` step in `examples/raster-titiler.ipynb` (#1327) should no longer be needed. That isn't tested here. - deck.gl: the MapLibre overlay container is removed with the overlay (visgl/deck.gl#10899), and `GlobeController` can zoom past level 12 (visgl/deck.gl#10737). The `beforeId` fix for interleaved MapLibre (visgl/deck.gl#10734) merged after 9.4.1, so the `idle` workaround tracked in #1293 stays. Supersedes Dependabot's #1350, which stops at deck.gl-raster 0.9.0. Closes #1350 ## Testing - `pnpm build`, `pnpm check` and `pnpm test` (12 tests) pass. - `uv run pytest` passes: 367 passed, 1 skipped, including `tests/ui`. - `tsc --noEmit` reports the same 9 errors as `main`, and no new ones. - No test covers `RasterLayer.from_geotiff`, the only path that uses deck.gl-raster's `RasterTileLayer`. I checked it by hand with a throwaway UI test. It opens a 2048×2048 EPSG:32618 COG with 3 overviews and renders it with no basemap. Tiles reach the canvas on this branch and on `main`, and the browser console output is the same on both. 🤖 Written by [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Released in deck.gl 9.4.2. Thanks @kylebarron! |
…s redundant (#886) > [!NOTE] > This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron. Closes #863 ### Problem deck.gl [9.4.2](https://github.com/visgl/deck.gl/releases/tag/v9.4.2) includes visgl/deck.gl#10883: - `Tileset2D.finalize` calls `onTileUnload` for every cached tile. - A tile whose load finishes after it left the cache is unloaded instead of reported loaded. Our workarounds for 9.4.1 do the same thing. On 9.4.2, they unloaded every tile twice. That destroyed default-pipeline textures twice and ran user `onTileUnload` / `onSourceUnload` callbacks twice (#863). With the lockfile moved to 9.4.2, five tests failed this way before this change. ### Change This is option 2 from #863: - Every `@deck.gl/*` spec, including peer deps, pnpm overrides and examples, now requires `^9.4.2`. The lockfile moves only deck.gl. - `RasterTileset2D`: removes the `finalize` override and the late-load guard from #878. The `abortUnwantedLoads` wrapper of `onTileUnload` stays. - `MosaicTileset2D`: removes the `finalize` override. `reloadAll` stays, because deck.gl's `reloadAll` still drops items without unloading them. It now calls deck.gl's `finalize`. - `custom-projection` example: removes its `finalize` override. - `MosaicLayer.onSourceUnload` docs: an item that is still opening is unloaded with no source, then again with its source once the open finishes. - `onnx-embeddings/NOTES.md`: no longer says the mid-load eviction leak applies. ### Test plan - [x] `deck.gl-raster` (263), `deck.gl-geotiff` (224) and `deck.gl-zarr` (81) tests pass on 9.4.2. - [x] One test encoded 9.4.1 behavior, with no unload at `finalize` for a loading tile. It now expects an unload right away with no content, then another once the data arrives. - [x] `biome ci` passes. - [ ] Not checked in a browser. Follow-up: switch the examples to `@deck.gl/maplibre` (#661), which visgl/deck.gl#10734 in 9.4.2 unblocks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011cLtCQHxJfGKqmXPYrjSPA Co-authored-by: Claude Opus 5.5 <[email protected]>
deck.gl 9.4.2 fixes `beforeId` on first load in `@deck.gl/maplibre` (visgl/deck.gl#10734), which blocked this switch in #661. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011cLtCQHxJfGKqmXPYrjSPA
> [!NOTE] > This PR was written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron. Needs deck.gl 9.4.2, from #886. Supersedes #661. ### Why deck.gl 9.4 adds `@deck.gl/maplibre`. #661 switched to it, but stayed a draft: with 9.4.0, interleaved layers that set `beforeId` were drawn above every MapLibre layer on first load (visgl/deck.gl#10733). visgl/deck.gl#10734 fixes that in 9.4.2. ### Change - The shared `DeckGlOverlay` uses `MapLibreOverlay` instead of `MapboxOverlay`. - `@deck.gl/mapbox` is replaced by `@deck.gl/maplibre` in `examples/_shared` and the root pnpm overrides. - The `@ts-expect-error` comments on `beforeId` now name `@deck.gl/maplibre`. ### Test plan - [x] `biome ci`, and `typecheck` and `build` of every example, pass. - [x] `cog-globe` in headless Chrome (SwiftShader), first load with no interaction: basemap labels and country borders draw above the raster, as `beforeId: "boundary_country_outline"` intends. That's the case that failed in #661. - [x] Every other example that uses `DeckGlOverlay`, in headless Chrome on a real GPU (GTX 950, ANGLE Vulkan), first load with no interaction: - Labels or borders draw above the deck.gl layers, as their `beforeId` intends: `aef-mosaic`, `cog-basic`, `dynamical-zarr-ecmwf`, `geoarrow-overlay`, `land-cover`, `naip-mosaic`, `nldas-icechunk`, `onnx-embeddings`, `pmtiles-terrain`, `titiler-cog`, `vermont-cog-comparison`, `vrt-mosaic`, `zarr-globe`. - No `beforeId`, so the layer draws on top, as before: `sentinel-2`, `usgs-topo`. - No console errors in any of them. Each logs `luma.gl: Binding sampler not set`; I didn't check whether `@deck.gl/mapbox` logs it too. - [ ] `zarr-sentinel2-tci` not checked: it reads from `http://localhost:8080/TCI.zarr`, which wasn't running. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011cLtCQHxJfGKqmXPYrjSPA Co-authored-by: Claude Opus 5.5 <[email protected]>


beforeIdis not currently handled correctly in the@deck.gl/maplibremodule because it tries to resolve the layer order before a JSON-based maplibre style has fully loaded.To fix this, we resolve the layer order once on the initial style input and again once the style has finished loading.
Closes #10733
Change List
sourcedatawhile layer group resolution is deferred, and detach once resolved, so tile and GeoJSON updates don't reconcile layer groups againsetPropslayer changes made while sources or tiles are loading (e.g. while panning), including removing layer groups that are no longer usedNote
Low Risk
Low risk fix scoped entirely to interleaved layer group lifecycle handling in the MapLibre module.
Overview
Defers interleaved layer group resolution in
MapLibreOverlaywhenmap.isStyleLoaded()is false, ensuring layer ordering (such asbeforeId) is applied once the style and its sources have finished loading.When resolution is deferred, the overlay listens for MapLibre's
sourcedataevent, applies pending layer groups once the style is ready, and immediately unbinds the listener to prevent redundant updates during subsequent tile or GeoJSON fetches. It also tracks_appliedLayersto guarantee correct layer diffing and cleanup if layer props update or the control is removed while sources are still loading.Reviewed by Cursor Bugbot for commit 69f963f. Bugbot is set up for automated code reviews on this repo. Configure here.