Skip to content

feat: fetch tiles again when updateTriggers.getTileData or ZarrLayer's selection changes - #818

Merged
kylebarron merged 10 commits into
mainfrom
kyle/refetch-tiles
Oct 29, 2026
Merged

kylebarron merged 10 commits into
mainfrom
kyle/refetch-tiles

Conversation

@kylebarron

@kylebarron kylebarron commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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 RasterTileLayer fetch their tiles again when updateTriggers.getTileData or updateTriggers.all changes. ZarrLayer also does when selection changes:

new ZarrLayer({ id: "temperature", source, selection: { time: t }, getTileData, renderTile });

Migration

Apps that put the selection in a ZarrLayer's id, or passed updateTriggers: { renderTile: [selection] }, can drop both:

// Before
new ZarrLayer({ id: `layer-${year}`, selection: { year }, ... });

// After
new ZarrLayer({ id: "layer", selection: { year }, ... });

Examples and docs

  • Examples:
    • aef-mosaic and dynamical-zarr-ecmwf drop the selection from their layer id.
    • The experimental ProjectedCOGLayer renders its own TileLayer in custom-projection views, and now puts the refetch count in that TileLayer's id too. _refetchTiles documents this for subclasses.
  • Docs:
    • The getTileData docs of RasterTileLayer, COGLayer and ZarrLayer say how to fetch the tiles again, and that deck.gl compares a trigger's elements with ===.
    • ZarrLayer's selection docs say that a new selection fetches them again.
  • Spec: records decision 24, and stage 4c as built.

Tests

  • RasterTileLayer, in deck.gl's LayerManager, with a real tile grid and viewport:
    • a changed updateTriggers.getTileData aborts every load in flight, unloads every tile, and fetches the visible tiles again;
    • a changed updateTriggers.all does the same;
    • an equal getTileData trigger keeps the tiles, and so does a changed renderTile trigger.
  • COGLayer, in deck.gl's LayerManager, with a COG fixture: a changed updateTriggers.getTileData aborts and unloads the loaded tile, and fetches it again. COGLayer inherits this from RasterTileLayer, since it overrides neither updateState nor renderLayers.
  • ZarrLayer: a new selection gets a new inner TileLayer; an equal one doesn't.
  • ProjectedCOGLayer: a refetch gets a new inner TileLayer.
  • Mutation checks: each of these fails a test:
    • ignoring all;
    • leaving the count out of the inner id;
    • not refetching on a trigger, in RasterTileLayer's build, for the COGLayer test;
    • not refetching on a new selection;
    • leaving the count out of ProjectedCOGLayer's id.
  • In Chrome: I counted live WebGL textures by wrapping createTexture and deleteTexture.
    • aef-mosaic:
      • switching the year removes the old tiles at once;
      • over 8 switches, two of them 300 ms apart, live textures stayed between 51 and 61, out of 335 created in all.
    • dynamical-zarr-ecmwf:
      • 250 ms after each forecast-date switch, live textures fall from 56 to 14, which are the basemap's;
      • they return to between 50 and 56 once the new run loads, over 6 switches;
      • the lead-time animation changes renderTile every 100 ms and creates no textures.

🤖 Written by Claude Code

kylebarron and others added 6 commits October 28, 2026 14:24
…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]>
@github-actions github-actions Bot added the feat label Oct 28, 2026
Comment on lines +510 to +512
* 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this is something we should fix upstream

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.tiles marked visible, so TileLayer keeps 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

Comment on lines +37 to +41
* 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work with no code changes here to COGLayer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • updateState calls _refetchTiles() when deck.gl reports that updateTriggers.getTileData or updateTriggers.all changed. deck.gl diffs the triggers on COGLayer's own props.
  • renderLayers puts 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}`,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels hacky but perhaps it's the best approach

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, _tiles and _selectedTiles, or calling finalize() 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

Comment on lines +109 to +115
* 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.
*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.
*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

kylebarron and others added 4 commits October 29, 2026 11:18
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]>

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅

@kylebarron
kylebarron merged commit 7a67a7f into main Oct 29, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/refetch-tiles branch October 29, 2026 15:40
kylebarron added a commit that referenced this pull request Oct 30, 2026
> [!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]>
kylebarron added a commit that referenced this pull request Nov 4, 2026
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]>
kylebarron added a commit that referenced this pull request Nov 5, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forward updateTriggers to the inner TileLayer, so tiles can be refetched

1 participant