fix(mosaic-layer): make sources prop reactive to updates#511
Merged
Conversation
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>
kylebarron
commented
May 7, 2026
kylebarron
commented
May 7, 2026
kylebarron
commented
May 7, 2026
- 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>
kylebarron
commented
May 7, 2026
Member
Author
kylebarron
left a comment
There was a problem hiding this comment.
This LGTM! I'll wait for @gadomski to check this against stac-map
Member
Author
|
I think this overall looks good; we can merge and revisit in case there's any unexpected behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MosaicTileset2Dnow takes a() => MosaicT[]getter instead of a snapshot array; the spatial index rebuilds lazily insidegetTileIndiceswhenever the closure returns a new array reference, picking up updates without recreating the tileset and preserving the inner tile cache.MosaicLayer.renderTileLayercloses overthis, passing() => self.props.sourcesso deck.gl's existingsetOptions→_viewport = null→getTileIndicesflow on every prop update naturally surfaces the new sources.MosaicLayerProps.sourcesandMosaicSource.x/y/znow 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
tests/mosaic-tileset.test.tscovers 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, explicitx/y/z, and zoom-range guards. 7/7 pass.pnpm exec biome checkclean onpackages/deck.gl-geotiff/src/mosaic-layer/and the new test file.pnpm exec tsc --noEmitreports no new errors in mosaic files (pre-existing workspace-build-order errors inmulti-cog-layer.tsandtests/{geotiff-tileset,render-pipeline}.test.tsare unchanged).stac-mapagainst the use case in Adding items to a mosaic layer #510 (continuously appending STAC search results to a singleMosaicLayer).🤖 Generated with Claude Code