Skip to content

fix(mosaic-layer): make sources prop reactive to updates#511

Merged
kylebarron merged 5 commits into
mainfrom
kyle/mosaic-layer-edit
May 7, 2026
Merged

fix(mosaic-layer): make sources prop reactive to updates#511
kylebarron merged 5 commits into
mainfrom
kyle/mosaic-layer-edit

Conversation

@kylebarron
Copy link
Copy Markdown
Member

Summary

  • MosaicTileset2D now takes a () => MosaicT[] getter instead of a snapshot array; the spatial index rebuilds lazily inside getTileIndices whenever the closure returns a new array reference, picking up updates without recreating the tileset and preserving the inner tile cache.
  • MosaicLayer.renderTileLayer closes over this, passing () => self.props.sources so deck.gl's existing setOptions_viewport = nullgetTileIndices flow on every prop update naturally surfaces the new sources.
  • Public JSDoc on MosaicLayerProps.sources and MosaicSource.x/y/z now documents the array-reference-equality contract and the cache-stability implications for append vs. reorder/middle-removal.

Closes #510.

Design doc: dev-docs/specs/2026-05-07-mosaic-layer-dynamic-sources-design.md.

Test plan

  • New tests/mosaic-tileset.test.ts covers initial query, append-without-reconstruction, empty → non-empty transition, in-place-mutation no-op (documents the reference-equality contract), default tile-id derivation from array position, explicit x/y/z, and zoom-range guards. 7/7 pass.
  • pnpm exec biome check clean on packages/deck.gl-geotiff/src/mosaic-layer/ and the new test file.
  • pnpm exec tsc --noEmit reports no new errors in mosaic files (pre-existing workspace-build-order errors in multi-cog-layer.ts and tests/{geotiff-tileset,render-pipeline}.test.ts are unchanged).
  • Smoke-test in stac-map against the use case in Adding items to a mosaic layer #510 (continuously appending STAC search results to a single MosaicLayer).

🤖 Generated with Claude Code

kylebarron and others added 2 commits May 7, 2026 09:50
Design for making MosaicLayer.sources reactive: pass a closure-over-layer
getter into MosaicTileset2D so the spatial index rebuilds in place when
the sources array reference changes. Preserves the inner Tileset2D's tile
cache across updates. Documents the array-position cache-stability
contract on the public JSDoc.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previously, MosaicLayer only rendered the sources array provided on
first mount; later updates were dropped because deck.gl's TileLayer
only instantiates TilesetClass once and the factory closed over a
snapshot of the sources array.

MosaicTileset2D now takes a `() => MosaicT[]` getter instead of a
sources array. The spatial index rebuilds lazily inside getTileIndices
when the closure-returned reference differs from the cached one,
piggybacking on the setOptions -> _viewport=null -> getTileIndices
flow that deck.gl already runs on every prop update. The inner
Tileset2D's tile cache survives across updates, so existing rendered
sub-layers are preserved on append.

Documents the array-position-based cache stability contract on the
public JSDoc for MosaicLayerProps.sources and MosaicSource x/y/z.

Closes #510.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the fix label May 7, 2026
Comment thread packages/deck.gl-geotiff/src/mosaic-layer/mosaic-layer.ts Outdated
Comment thread packages/deck.gl-geotiff/src/mosaic-layer/mosaic-tileset-2d.ts Outdated
Comment thread packages/deck.gl-geotiff/src/mosaic-layer/mosaic-tileset-2d.ts Outdated
kylebarron and others added 3 commits May 7, 2026 10:09
- mosaic-layer.ts: hoist the sources getter out of the factory class so
  its lexical `this` is the MosaicLayer instance directly; the explicit
  `const self = this` alias is no longer needed.
- mosaic-tileset-2d.ts: collapse the {sources, index} state into a single
  `cached` field and have `ensureIndex` return the prepared
  `BuiltIndex<MosaicT> | null`. Eliminates the non-null assertion at the
  query site and reduces field count from 4 to 3.
- mosaic-tileset-2d.ts: per-field JSDoc on `getSources`, `cachedRaw`,
  `cached` documenting their roles.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member Author

@kylebarron kylebarron left a comment

Choose a reason for hiding this comment

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

This LGTM! I'll wait for @gadomski to check this against stac-map

@kylebarron
Copy link
Copy Markdown
Member Author

I think this overall looks good; we can merge and revisit in case there's any unexpected behavior

@kylebarron kylebarron merged commit 220e02c into main May 7, 2026
3 checks passed
@kylebarron kylebarron deleted the kyle/mosaic-layer-edit branch May 7, 2026 19:36
@kylebarron kylebarron restored the kyle/mosaic-layer-edit branch May 7, 2026 20:44
@kylebarron kylebarron deleted the kyle/mosaic-layer-edit branch May 7, 2026 20:45
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.

Adding items to a mosaic layer

1 participant