Skip to content

Progressive sync: nested toArray subqueries skip the fast-path snapshot #1533

@ibirrer

Description

@ibirrer
  • I've validated the bug against the latest version of DB packages

Describe the bug

In progressive sync mode, a collection queried directly with a where predicate loads the
matching subset first (fast path) and the rest of the collection in the background. But when the
same collection is fetched as a nested toArray child of another collection, there is no fast-path
step — the nested rows only become available once the entire child collection has finished its
background sync.

For example, querying posts directly, filtered to one user, shows that user's posts almost
immediately. Fetching the same posts as a nested child of that user shows them only after every post
of every user has loaded.

Reproducible with these tests:

Steps to Reproduce

// posts is an Electric collection with syncMode: 'progressive'

// Direct query — fast path works:
const direct = createLiveQueryCollection((q) =>
  q.from({ post: posts }).where(({ post }) => eq(post.userId, userIdParam)),
);

// Nested query — no fast path:
const nested = createLiveQueryCollection((q) =>
  q
    .from({ user: users })
    .where(({ user }) => eq(user.id, userIdParam))
    .select(({ user }) => ({
      ...user,
      posts: toArray(q.from({ post: posts }).where(({ post }) => eq(post.userId, user.id))),
    })),
);

Observed Behavior

  • The direct query loads the matching subset via the fast-path snapshot, then the rest in the
    background.
  • The nested query loads the whole posts collection at once; the nested array stays empty until
    the full background sync completes.
  • No error or warning is thrown — the data is correct, just slow.

Expected Behavior

Fetching a collection as a nested toArray child should get the same progressive fast-path as
querying it directly: the matching subset should load first, the rest in the background.

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