Skip to content

Join queries with on-demand sync collections don't load initial data #1077

Description

@ibarakaiev

When using syncMode: 'on-demand' collections in a join query, the "lazy" side of the join never receives data.

Reproduction

// All collections use syncMode: 'on-demand' with Electric (offset: 'now')
const { data } = useLiveQuery((query) =>
  query
    .from({ users: usersCollection })
    .leftJoin({ memberships: membershipCollection }, ({ users, memberships }) =>
      eq(users.id, memberships.userId)
    )
);
// Result: empty array, even though data exists in the database

Workaround
Trigger sync on the lazy collection before the join query:

useUsers(); // Simple query that triggers usersCollection sync
// Then the join query works

In collection-subscriber.ts, subscribeToMatchingChanges() only calls requestSnapshot() when includeInitialState is true. For lazy aliases in joins, includeInitialState is false, so on-demand collections never trigger data loading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions