fix: default getKey on live query collections fails on enriched objects#1432
Merged
fix: default getKey on live query collections fails on enriched objects#1432
Conversation
The default WeakMap-based getKey for live query collections breaks when enriched change values (with virtual props) are passed through chained collections. The enriched objects are new references not found in the WeakMap, causing all items to resolve to key `undefined` and collide. Fall back to `item.$key` (set by virtual props enrichment) when the WeakMap lookup misses. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: +7 B (+0.01%) Total Size: 113 kB 📦 View Changed
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 4.23 kB ℹ️ View Unchanged
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
samwillis
approved these changes
Mar 30, 2026
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
getKeyfor live query collections breaks when a live query collection (without a customgetKey) is used as a source in another live query collection. Virtual props enrichment creates new object references that miss the WeakMap, causing all items to resolve to keyundefinedand collapse into a single item.item.$key(already set by virtual props enrichment) when the WeakMap lookup misses.getKey: simple query, join query, and update propagation.Fixes #1423
Test plan
live-query-collection.test.tssuite passes (52/52)🤖 Generated with Claude Code