Repository navigation
feat: fetch tiles again when updateTriggers.getTileData or ZarrLayer's selection changes - #818
Conversation
…ta changes A change to `updateTriggers.getTileData` or `updateTriggers.all` now drops every tile at once and fetches the visible ones again. Before, no trigger reached the inner TileLayer, so cached tiles kept their old data. Each refetch gives the inner TileLayer a new id. deck.gl removes the old one, and its tileset aborts the loads in flight and unloads every tile. deck.gl's own reload, `Tileset2D.reloadAll`, isn't used: it keeps drawing old tiles, and drops or replaces their data without `onTileUnload`. Subclasses call `_refetchTiles()` when something their `getTileData` reads changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changing ZarrLayer's `selection` now drops the old selection's tiles at once and fetches the visible ones again. Before, loaded tiles kept the data they were fetched with, so apps put the selection in the layer `id` to start over. Selections are still compared by value, through the pair the layer last checked, so an inline literal with the same contents fetches nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
aef-mosaic and dynamical-zarr-ecmwf put the year and the init time in their ZarrLayer's `id`, so a new selection started a new layer with no cached tiles. ZarrLayer now fetches its tiles again when `selection` changes, so the ids are fixed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Decision 24: a refetch replaces the inner TileLayer, and the old tiles go at once. deck.gl's `reloadAll` isn't used, since in 9.4 it keeps drawing the tiles it drops and leaks their data. MosaicLayer's part of #797 is #816. Co-Authored-By: Claude Opus 5.5 <[email protected]>
COGLayer and ZarrLayer redeclare `getTileData`, so their docs didn't carry `RasterTileLayer`'s note on `updateTriggers.getTileData`. Each now says how to fetch the tiles again, and that deck.gl compares a trigger's elements with `===`. A new object in a trigger would fetch every tile again on every render. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In custom-projection views, ProjectedCOGLayer renders its own TileLayer, whose id didn't include the refetch count, so `updateTriggers.getTileData` fetched nothing there. `_refetchTiles` now documents that a subclass rendering its own TileLayer puts `state.refetchCount` in its id. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| * deck.gl's own reload, `Tileset2D.reloadAll`, would keep drawing old tiles. | ||
| * It also drops or replaces their data without `onTileUnload`, so their | ||
| * textures would leak. |
There was a problem hiding this comment.
perhaps this is something we should fix upstream
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Agreed, these are upstream bugs, and deck.gl master has the same reloadAll as 9.4.0. Your visgl/deck.gl#10883 covers one case: a tile that reloadAll drops while it's still loading is unloaded when its data arrives. Still broken upstream:
- the tiles it drops after they loaded are never unloaded, and they stay in
tileset.tilesmarked visible, soTileLayerkeeps drawing them; - the data a reload replaces is never unloaded.
I've drafted an issue for visgl/deck.gl with a short Node repro. I haven't posted it; it's yours to review first.
Even with those fixed, we'd keep a new TileLayer per refetch. deck.gl's reload keeps old tiles drawn until their replacements load, on purpose (visgl/deck.gl#6194), and you wanted the old data gone at once.
99691b3 cuts this paragraph down to one line that points to this PR.
🤖 Written by Claude Code
| * To fetch the tiles again when something this function reads changes, | ||
| * change `updateTriggers.getTileData` (or `updateTriggers.all`). The | ||
| * layer drops every tile at once and fetches the visible ones again. | ||
| * deck.gl compares each element of a trigger with `===`, so keep them | ||
| * the same across renders, or every render fetches every tile again. |
There was a problem hiding this comment.
how does this work with no code changes here to COGLayer?
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
COGLayer inherits it. The refetch lives in two RasterTileLayer methods that COGLayer doesn't override:
updateStatecalls_refetchTiles()when deck.gl reports thatupdateTriggers.getTileDataorupdateTriggers.allchanged. deck.gl diffs the triggers on COGLayer's own props.renderLayersputs the refetch count in the inner TileLayer's id.
COGLayer overrides only the hooks for its source, its tile callbacks and its unload callback.
The PR had no COGLayer test of this, so 1cf665e adds one in deck.gl's LayerManager, with a COG fixture: a changed trigger aborts and unloads the tile, and fetches it again. The test fails if RasterTileLayer's build stops refetching.
🤖 Written by Claude Code
| // new descriptor needs a new TileLayer | ||
| id: `raster-tile-layer-${this.id}-${descriptorId(descriptor)}`, | ||
| // new descriptor needs a new TileLayer. So does each refetch. | ||
| id: `raster-tile-layer-${this.id}-${descriptorId(descriptor)}-${this.state?.refetchCount ?? 0}`, |
There was a problem hiding this comment.
This feels hacky but perhaps it's the best approach
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
A new id is how deck.gl starts any layer over, like React's key, and this layer already does it for a new tile grid. deck.gl's own TileLayer used to do the same: until visgl/deck.gl#6194 (2021), it built a new tileset when a getTileData trigger changed. It switched to reloadAll so that old tiles stay drawn while new ones load (visgl/deck.gl#6179), which is the opposite of what you want here.
The alternatives cost more:
- deck.gl's reload keeps old tiles drawn by design, and leaks (see the thread above).
- Clearing the tileset in place needs deck.gl's private
_cache,_tilesand_selectedTiles, or callingfinalize()on a tileset the TileLayer keeps using.
Beyond re-meshing the visible tiles, which any approach that drops the old data pays, a new id has one cost: the new tileset's bounding-volume cache starts empty. In a quick Node measurement on a NAIP-sized UTM image, the first traversal after a refetch took 1.8-2.4 ms instead of 0.05-0.09 ms. If that ever matters, the cache could be shared per tile grid.
So I'd keep it.
🤖 Written by Claude Code
| * change `updateTriggers.getTileData` (or `updateTriggers.all`). The layer | ||
| * drops every tile at once, so the old data is never drawn after the | ||
| * change, and fetches the visible tiles again. deck.gl compares each | ||
| * element of a trigger with `===`, so keep them the same across renders: | ||
| * a new object in one, such as `[{ time }]`, fetches every tile again on | ||
| * every render. | ||
| * |
There was a problem hiding this comment.
| * change `updateTriggers.getTileData` (or `updateTriggers.all`). The layer | |
| * drops every tile at once, so the old data is never drawn after the | |
| * change, and fetches the visible tiles again. deck.gl compares each | |
| * element of a trigger with `===`, so keep them the same across renders: | |
| * a new object in one, such as `[{ time }]`, fetches every tile again on | |
| * every render. | |
| * | |
| * change `updateTriggers.getTileData` (or `updateTriggers.all`). deck.gl compares each | |
| * element of a trigger with `===`, so keep them the same across renders. | |
| * |
There was a problem hiding this comment.
more concise docstrings are better. We don't need to explain all effects of every change. I.e. a user or agent should know the implications of instance equality
There was a problem hiding this comment.
Note
This reply was written by Claude (Claude Code), not by @kylebarron.
Applied in 99691b3, wrapped to 80 columns. I cut the other docs this PR added the same way: getTileData on COGLayer and ZarrLayer, ZarrLayer's selection, and _refetchTiles with its state field.
🤖 Written by Claude Code
Each doc now says how to fetch the tiles again and that a trigger's elements are compared with `===`, without listing what follows from it. The reason `_refetchTiles` doesn't use deck.gl's `reloadAll` is a pointer to #818. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…trigger COGLayer inherits the refetch from RasterTileLayer: it overrides neither `updateState` nor `renderLayers`. This pins that in deck.gl's LayerManager, with a COG fixture: a changed `updateTriggers.getTileData` aborts and unloads the loaded tile, and fetches it again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#809 gave COGLayer a 50 ms request debounce by default, so the test's loads hadn't started when it checked them, after merging main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
> [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. Bumps `version` to `0.10.0-beta.1` in the root `package.json` and in every `packages/*/package.json`, ready for the first 0.10 beta. The publish workflow sees `beta` in the version and publishes to npm under the `beta` dist-tag, so `latest` stays on 0.9.0. `CHANGELOG.md` gets a `v0.10.0-beta.1` section listing the 19 PRs merged since v0.9.0. ## Publish `@developmentseed/range-reader` by hand before tagging `@developmentseed/range-reader` (#806) isn't on npm yet, and `@developmentseed/geotiff` and `@developmentseed/deck.gl-geotiff` depend on it. The publish workflow can't create it: it publishes only through trusted publishing (OIDC), and npm can add a trusted publisher only to a package that [already exists](https://docs.npmjs.com/cli/v11/commands/npm-trust). Pushing the tag first would fail at `range-reader`. `pnpm publish --recursive` stops at the first failure, so packages published before it in the run would be out, and the rest, including `geotiff` and `deck.gl-geotiff`, would not. Once this is merged, from an up-to-date `main`: 1. Publish it once, as a public package under the `beta` tag. Its `prepublishOnly` script builds it first. ```sh cd packages/range-reader pnpm publish --tag beta --access public --no-git-checks ``` 2. Give it the same trusted publisher as the other packages (workflow `release.yml`, environment `release`), in its settings on npmjs.com or with: ```sh npm trust github @developmentseed/range-reader --file release.yml --repo developmentseed/deck.gl-raster --env release --allow-publish ``` 3. Tag the merge commit `v0.10.0-beta.1` and push the tag. The workflow skips `range-reader`, since that version is already on npm, and publishes the other ten packages. ## Breaking changes - #799: `COGLayer` takes a single `source`: an opened `COGSource`, or any input of `COGSource.open`. `geotiff` becomes `source`, `onGeoTIFFLoad` becomes `onSourceLoad`, and `epsgResolver` and `concurrencyLimiter` move to `COGSource.open`. - #801: `MultiCOGLayer` does the same with `MultiCOGSource`. `sources: { red: { url } }` becomes `source: { red: url }`, `MultiCOGSourceConfig` is removed, and files that don't share a CRS and an extent are rejected. - #804: `MosaicLayer`'s `sources` becomes deck.gl's `data`, and `MosaicSource` becomes `MosaicItem`. The callbacks get the item's opened source as `source`, and `onViewportLoad`'s entries are `{ item, source }`. - #821: `renderSource` gets only `{ source }`, without `signal`. - #812: `ZarrLayer` takes a `ZarrSource`, or a zarrita group or array, as `source`. `node`, `variable`, `metadata` and `epsgResolver` are removed (`metadata` becomes `ZarrSource.open`'s `geoZarrMetadata`), and the type parameters are now `ZarrLayer<DataT, Dtype, Store>`. - #807: `GeoTIFF.fromUrl` no longer takes `chunkSize` or `cacheSize`. They're `RangeReader` options now (`minMetadataReadBytes`, `cache.metadataBytes`). Two behavior changes aren't marked breaking: - #809: COG tile reads are coalesced by default, and `COGLayer` and `MultiCOGLayer` default to `maxRequests: 256` and `debounceTime: 50`. - #818: changing `updateTriggers.getTileData`, or ZarrLayer's `selection`, fetches tiles again, and the old tiles are removed at once. 🤖 Written by [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
Port zarr-globe to the ZarrLayer API from #812, as dynamical-zarr-ecmwf was ported there: open the array with `ZarrSource.open` and the GeoZarr attrs, pass the source as `source`, and use the `ZarrLayer<DataT, Dtype>` type parameter order. Drop `initTimeIdx` from the layer id, since changing `selection` now fetches tiles again (#818). Match dynamical-zarr-ecmwf's dependency versions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iggers.getSource changes (#848) > [!NOTE] > This PR was written by Claude (Claude Code), not by @kylebarron. `MosaicLayer` caches the source that `getSource` opens for each item. Until now, nothing opened those sources again. When something `getSource` reads changed, loaded items kept their old sources and only items loaded afterward used the new ones, so the mosaic could show a mix of both. Now a change to `updateTriggers.getSource` or `updateTriggers.all` opens every source again: ```ts new MosaicLayer({ data: items, getSource: (item, options) => COGSource.open(item.assets[band].href, options), updateTriggers: { getSource: band }, renderSource: (item, { source, subLayerProps }) => new COGLayer({ ...subLayerProps, source }), }); ``` - **How it works:** - MosaicLayer hands `updateTriggers.getSource` to its inner `TileLayer` as `updateTriggers.getTileData`, and `all` as `all`. When either changes, deck.gl's `TileLayer` calls the tileset's `reloadAll`, as it does upstream. - `MosaicTileset2D` overrides `reloadAll`. It unloads every source through `finalize` (#823), which also aborts the opens in flight. Then it makes the next update select the items in view again, and they open with the current `getSource`. Items out of view are opened when they come back. - **The old items stop drawing at once,** as #818's tiles do. - **A new `getSource` function alone opens nothing again,** as with deck.gl's accessors. - **deck.gl's own `reloadAll` is replaced** (#816): - It drops items out of view without unloading them, and keeps them in `tileset.tiles`. - It keeps drawing the items in view with their old sources until the new ones open, and never unloads the old ones. - The override stays until we adopt deck.gl v10's shared `Tileset2D` (#846). Its `reloadAll` unloads the tiles it drops, but still not the data a reload replaces. `renderSource` gets no trigger. Every render of MosaicLayer already draws the loaded items again with the current `renderSource`, and #844 tests that. RasterTileLayer still refetches through a count in its inner `TileLayer`'s id (#818). A follow-up moves it to the same override. ## Changes - **`MosaicLayer`** passes the two triggers to its inner `TileLayer`, and stores nothing. - **`MosaicTileset2D`** overrides `reloadAll`. - **Docs:** `getSource`'s docs say when and how to open the sources again. - **Spec:** decision 26 records this and the `renderSource` decision. The 4c entry points to it. ## Tests - **Runtime**, through deck.gl's `LayerManager`: - A change to `updateTriggers.getSource`, and to `updateTriggers.all`, opens every source again with the new `getSource`, and passes the old sources to `onSourceUnload`. - An unchanged trigger opens nothing again, even with a new `getSource` function. - The old items stop drawing at once, before the new sources open. - **`MosaicTileset2D`:** `reloadAll` unloads every item, and the next update selects the items in view again, even though the viewport hasn't changed. - **Replaced test:** #789 had a test that `all` doesn't open the sources again. `all` now opens them again, through the override instead of deck.gl's `reloadAll`. - **Mutation checks:** - Without the `setOptions` call in the override, 1 test fails. - Without the `getTileData` trigger, 2 tests fail. - Without the `all` trigger, 1 test fails. - Without the override, 4 tests fail. - **Everything else:** all 222 `deck.gl-geotiff` tests pass, as do the workspace typecheck and Biome. In Chrome, naip-mosaic still loads and pans with no errors. Closes #816 🤖 Written by [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
Stage 4c of the Sources design (
dev-docs/specs/2026-10-22-sources-design.md, decision 24). Closes #797.Layers built on
RasterTileLayerfetch their tiles again whenupdateTriggers.getTileDataorupdateTriggers.allchanges.ZarrLayeralso does whenselectionchanges:The old tiles go at once. Where new tiles haven't loaded yet, the map shows nothing rather than the old selection's data.
How: each refetch gives the inner TileLayer a new id. deck.gl removes the old one, and its tileset aborts the loads in flight and unloads every tile (fix(deck.gl-raster): destroy tile textures when a raster layer is removed #728). Subclasses call the new protected
_refetchTiles().Selections are compared by value, so an inline
{ time: t }with the same contents fetches nothing. A change toupdateTriggers.renderTilestill only redraws.Not deck.gl's reload: a
getTileDatatrigger on deck.gl'sTileLayercallsTileset2D.reloadAll. In 9.4 that:onTileUnload;tileset.tiles, still marked visible;onTileUnload.Forwarding the triggers, as Forward updateTriggers to the inner TileLayer, so tiles can be refetched #797 proposed, would leak textures and draw stale tiles.
MosaicLayer builds its own TileLayer. Its part of Forward updateTriggers to the inner TileLayer, so tiles can be refetched #797 is MosaicLayer can't open its sources again through updateTriggers #816.
Migration
Apps that put the selection in a ZarrLayer's
id, or passedupdateTriggers: { renderTile: [selection] }, can drop both:Examples and docs
id.ProjectedCOGLayerrenders its own TileLayer in custom-projection views, and now puts the refetch count in that TileLayer's id too._refetchTilesdocuments this for subclasses.getTileDatadocs ofRasterTileLayer, COGLayer and ZarrLayer say how to fetch the tiles again, and that deck.gl compares a trigger's elements with===.selectiondocs say that a new selection fetches them again.Tests
RasterTileLayer, in deck.gl'sLayerManager, with a real tile grid and viewport:updateTriggers.getTileDataaborts every load in flight, unloads every tile, and fetches the visible tiles again;updateTriggers.alldoes the same;getTileDatatrigger keeps the tiles, and so does a changedrenderTiletrigger.COGLayer, in deck.gl'sLayerManager, with a COG fixture: a changedupdateTriggers.getTileDataaborts and unloads the loaded tile, and fetches it again. COGLayer inherits this fromRasterTileLayer, since it overrides neitherupdateStatenorrenderLayers.ZarrLayer: a new selection gets a new inner TileLayer; an equal one doesn't.ProjectedCOGLayer: a refetch gets a new inner TileLayer.all;RasterTileLayer's build, for the COGLayer test;ProjectedCOGLayer's id.createTextureanddeleteTexture.renderTileevery 100 ms and creates no textures.🤖 Written by Claude Code