Skip to content

TypeError: Cannot read properties of undefined (reading 'Symbol(liveQueryInternal)') when calling .update() on a queryCollection #1599

Description

@mwalkersigma
  • [ X ] I've validated the bug against the latest version of DB packages

Describe the bug
Calling .update() on a collection created with createCollection(queryCollectionOptions(...)) throws a TypeError at sync.ts:156 during the sync reconciliation step. The error occurs because the sync code unconditionally accesses utils[LIVE_QUERY_INTERNAL] on the collection config, but LIVE_QUERY_INTERNAL is only present on collections created with liveQueryCollectionOptions — not queryCollectionOptions.

Despite the error, the mutation does reach the server — changes persist on reload — so this appears to be a client-side reconciliation issue only.

To Reproduce
const surplusProductCollection = createCollection(queryCollectionOptions({ myConfig }));

const {data: modelDetails} = useLiveQuery(q => {
if (!selectedModelId) {
return undefined;
}
return q
.from({model: surplusModelCollection})
.where(({model}) => eq(model.id, selectedModelId))
.join({product: surplusProductCollection}, ({product, model}) => eq(
model.id, product.model_id
))
})
const product = modelDetails?.product;
// Calling .update() triggers the error
surplusProductCollection.update(product.id, (draft) => {
draft.category_id = Number(value);
});

Expected behavior
.update() should work on queryCollection without throwing. The LIVE_QUERY_INTERNAL symbol access should be guarded — if the collection was not created with liveQueryCollectionOptions, the sync reconciliation path should treat hasCustomGetKey, hasJoins, and hasDistinct as false (or skip the check entirely).

Error
Uncaught TypeError: Cannot read properties of undefined (reading 'Symbol(liveQueryInternal)')
at Object.write (sync.ts:156:36)
at flushIncludesState (collection-config-builder.ts:1675:33)
at Object.flushPendingChanges (collection-config-builder.ts:816:7)
at CollectionConfigBuilder.maybeRunGraph (collection-config-builder.ts:381:21)
at CollectionConfigBuilder.executeGraphRun (collection-config-builder.ts:578:10)
at run (collection-config-builder.ts:506:23)
at Scheduler.schedule (scheduler.ts:79:7)
at CollectionConfigBuilder.scheduleGraphRun (collection-config-builder.ts:502:32)
at CollectionSubscriber.sendChangesToPipeline (collection-subscriber.ts:176:34)
at sendChanges (collection-subscriber.ts:189:12)
at CollectionSubscription.callbackWithSentKeysTracking (subscription.ts:126:7)
at CollectionSubscription.emitEvents (subscription.ts:331:12)
at CollectionChangesManager.emitEvents (changes.ts:113:20)
at CollectionStateManager.recomputeOptimisticState (state.ts:695:20)
at CollectionMutationsManager.update (mutations.ts:455:11)
at CollectionImpl.update (index.ts:764:28)
at Object.onUpdate (WithDetailedModelCard.tsx:346:58)
at handleSave (main.tsx:208:19)

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: PC
  • OS: Windows
  • Browser Chrome
  • Package: @tanstack/react-db
  • Version 0.1.86
    Additional context
    Relevant source code

const utils = this.config.utils as Partial
const internal = utils[LIVE_QUERY_INTERNAL] // undefined for queryCollection
throw new DuplicateKeySyncError(key, this.id, {
hasCustomGetKey: internal?.hasCustomGetKey ?? false, // TypeError here
hasJoins: internal?.hasJoins ?? false,
hasDistinct: internal?.hasDistinct ?? false,
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions