Skip to content
Source
Sign inSign up
TanStack/db

Include value updates break with solidjs #1571

Send to my agent
ClosedTarmean(GitHub profile, opens in a new tab) opened this issue 1 comment
  • I've validated the bug against the latest version of DB packages (@tanstack/solid-db@0.2.1 with @tanstack/db@0.6.7)

Describe the bug

In solid-db's useLiveQuery, toArray includes are not reactive. For query includes, if the initial include is empty it starts as a non-observable null value. In this case the child query is also not reactive.

To Reproduce Steps to reproduce the behavior:

  • Create two empty collections
  • Create a query which has an include between them
  • Create a solidjs subscription on the query
  • Fill the empty collections (not in a single solidjs batch so solid sees an intermediate value)

For a query with an toArray include the initial collection does not have to be empty, the include is never reactive.

Expected behavior That solidjs updates when the include changes

Additional context

flushIncludesState clones the rows for the events.

But solidjs reads currentCollection.values() on any update, and these rows are updated in place. Since the pointers are stable, reconcile prunes them and nothing downstream sees the update. This is relevant when the update is a value (e.g. toArray), or if the initial include collection was empty. In that case the include field starts as null and solidjs doesn't see the change to a non-null reference.

https://github.com/TanStack/db/blob/be656be5c5fa65cc1c2bf76bc0b60be3d9d2a577/packages/solid-db/src/useLiveQuery.ts#L349

If an include is initially empty, the proxy is not attached to the parent. It remains null. This is why the initial child field can be null, breaking reactivity for collection includes as well.

https://github.com/TanStack/db/blob/be656be5c5fa65cc1c2bf76bc0b60be3d9d2a577/packages/db/src/query/live/collection-config-builder.ts#L1851-L1867

  1. Tarmean(GitHub profile, opens in a new tab) changed the title

  2. Closing as completed by https://github.com/TanStack/db/pull/1785 (https://github.com/TanStack/db/commit/a378bd3a65f6b9ed0c9a85f793b7dc2e2a59a313). Solid now republishes rendered toArray child-value changes and reacts when an initially empty Collection-valued include receives its first row. Both cases have permanent regression coverage.

Sign in to join this conversation.