Skip to content
Source
Sign inSign up
TanStack/db

Query Driven sync doesn't pass filters when being used in includes #1441

Send to my agent
Closedparthverma1(GitHub profile, opens in a new tab) opened this issue 1 comment
  • I've validated the bug against the latest version of DB packages

Describe the bug When using the nested UI queries as announced here, the where clause is not passed to the queryFn via loadSubsetOptions. This means all the data needs to be fetched thus eliminating the benefits of partial data fetching.

To Reproduce

const root = createCollection(
  queryCollectionOptions({
    queryKey: ['root'],
    syncMode: 'on-demand',
    queryFn: async (context) => {
      return getRoots();
    },
    queryClient,
    getKey: (item) => item.id,
  })
);

const items = createCollection(
  queryCollectionOptions({
    queryKey: ['root-items'],
    syncMode: 'on-demand',
    queryFn: async (context) => {
      const { filters } = parseLoadSubsetOptions(
        context.meta?.loadSubsetOptions
      );
      const rootId = filters[0].value; // <- This is never defined
      const items = await getRootItems(filters[0].value)
    },
    queryClient,
    getKey: (item) => item.id,
  })
);


const collection = await queryOnce((q) => {
  const c = q
    .from({ r: root })
    .select(({ r }) => ({
      id: collection.id,
      name: collection.title,
      children: toArray(
        q
          .from({ items: items })
          .where(({ items }) => eq(items.rootId, r.id))
          .select(({ items }) => ({
            id: items.id,
            type: items.type,
            name: items.title,
          }))
      ),
    }));
  return c;
});

Expected behavior rootId should be defined in the queryFn

Desktop (please complete the following information):

  • OS: [e.g. iOS]: macOS Tahoe 26.2
  • Browser [e.g. chrome, safari]: chrome
  • Version [e.g. 22]: 146.0.7680.167

Additional context Add any other context about the problem here.

Sign in to join this conversation.