Skip to content

fix(deck.gl-geotiff): call onSourceUnload for MosaicLayer's cached sources when it's removed - #823

Merged
kylebarron merged 2 commits into
mainfrom
kyle/mosaic-unload-on-finalize
Oct 30, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/mosaic-unload-on-finalize

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

When a MosaicLayer is removed, onSourceUnload now fires for every source the layer still holds.

deck.gl's Tileset2D.finalize clears its cache without calling onTileUnload, so MosaicLayer never reported those sources. MosaicTileset2D now unloads every cached item on finalize, as RasterTileset2D does for tiles (#728). An item still opening is unloaded once its open finishes, since deck.gl keeps what an aborted open returns anyway.

This is the first step toward #816. Re-opening sources through updateTriggers will replace MosaicLayer's inner TileLayer, which drops its cache the same way.

The override repeats RasterTileset2D.finalize. visgl/deck.gl#10883 would make deck.gl do this itself, and then both could go.

Ref #816

Tests

These run in deck.gl's LayerManager, and both failed before the fix:

  • removing the layer passes each loaded item's source to onSourceUnload;
  • an item still opening at removal is passed to it once its source arrives. Unloading the item right away instead fails this test.

🤖 Written by Claude Code

…urces when it's removed

deck.gl's `Tileset2D.finalize` clears its cache without `onTileUnload`, so
removing a MosaicLayer never called `onSourceUnload` for the sources it
still held. MosaicTileset2D now unloads every cached item on finalize, as
RasterTileset2D does (#728). An item still opening is unloaded once its
open finishes, since deck.gl keeps what an aborted open returns anyway.

Part of #816.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 30, 2026
Comment on lines +88 to +89
* Unloads every cached item, which deck.gl's `finalize` skips (see #728). An
* item still opening is unloaded once its open finishes.

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.

We should point to visgl/deck.gl#10883 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.

Done in 53581a1. This docstring now points to visgl/deck.gl#10883. I added the same pointer to RasterTileset2D.finalize, which works around the same deck.gl gap, so both overrides say they can go once #10883 lands.

🤖 Written by Claude Code

@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 3b6d3ca into main Oct 30, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/mosaic-unload-on-finalize branch October 30, 2026 15:27
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.2` in the root `package.json` and in
every `packages/*/package.json`. The publish workflow publishes it under
the `beta` dist-tag, so `latest` stays on 0.9.0.

`CHANGELOG.md` gets a `v0.10.0-beta.2` section with the one PR merged
since v0.10.0-beta.1, #823.

## Before pushing the tag

`@developmentseed/range-reader` needs a trusted publisher on npm, with
the same settings as the other packages: workflow `release.yml`,
environment `release`. The v0.10.0-beta.1 publish run failed at
`range-reader` without one, after it had published `affine`, `epsg` and
`proj`.

🤖 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 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.

1 participant