You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dev warning when a live query captures a value with only reference identity (silent empty results or render loops) #2462
Split out of #2459 (its requirement 2), so that #2460 can close #2459 with value equality for classes with toJSON().
Describe the bug
When a value captured in a live query has only reference identity (a class instance with no stable serialization), the query fails silently:
eq(user.id, someInstance) with an equal but distinct instance reports status: 'ready' / isReady: true with no rows, while the source collection holds the matching row. Nothing is thrown or logged.
If the instance is constructed during render (for example new RecordId('user', params.id) in the component body) and there is no queryKey, each render gets a new runtimeReference identity, so useLiveQuery builds a new live query on every render and never settles. aron-intframe measured 5000 renders in about 1.1s, still loading, with React 19.3.1 and jsdom (see Query identity/hashing: support class instances with a stable serialization (e.g. toJSON), such as SurrealDB RecordId #2459). The only signal is the dev warning about deriving identity on a hot render path, which recommends queryKey but doesn't say which captured value keeps changing.
#2460 gives classes with toJSON() value identity and value equality, which covers record-id types such as SurrealDB's RecordId. Other classes (no toJSON(), or ones that toJSON() can't represent) still get reference identity, so these failure modes remain for them.
To Reproduce
import{createCollection,localOnlyCollectionOptions,createLiveQueryCollection,eq}from'@tanstack/db'classId{constructor(table,key){this.table=table;this.key=key}// no toJSON(), so no stable serialization}constusers=createCollection(localOnlyCollectionOptions({id: 'users',getKey: (u)=>`${u.id.table}:${u.id.key}`,initialData: [{id: newId('user','abc'),name: 'A'}],}))constlq=createLiveQueryCollection((q)=>q.from({user: users}).where(({ user })=>eq(user.id,newId('user','abc'))))awaitlq.preload()lq.status// 'ready'lq.toArray.length// 0, with nothing logged
Expected behavior
In development, when a captured value can only be identified by reference, log a warning (or throw, behind an option) that names the value's path in the query and points at the fixes: pass a stable value, give the class a toJSON(), or set queryKey. For the render-loop case, the existing hot-path warning could name the captured value whose identity changes between renders.
Activity