Skip to content
Source
Sign inSign up
TanStack/db

useLiveInfiniteQuery is not updated after deletions on descending order when page is undersized #872

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

Describe the bug When using useLiveInfiniteQuery with orderBy(..., 'desc'), deleting an item from the current page does not update the live result if the page has fewer rows than pageSize. The item disappears in storage but remains in the hook’s data until something else changes.

To Reproduce

  1. Build a descending infinite query (e.g. messages ordered by id desc, pageSize N).
  2. Ensure the current page has < pageSize items (e.g. last page).
  3. Delete one item.
  4. Observe the hook still returns the deleted item; data never refills.

I created an example in stackblitz so you can understand the issue easier: https://stackblitz.com/edit/vitejs-vite-zhiz8bwg

Expected behavior After a delete, the hook should fetch the next item in order and the deleted row should disappear.

Code If you have a live infinite query like this and the response has less than 20 items, deletes do not updated the result. If you change the order to asc it works.

const messageListQuery = useLiveInfiniteQuery(
    (q) =>
      q
        .from({ messages: messagesCollection })
        .orderBy(({ messages }) => messages.id, 'desc'),
    {
      pageSize: 20,
      getNextPageParam: (lastPage, allPages) =>
        lastPage.length === 20 ? allPages.length : undefined,
    },
    []
  );

Sign in to join this conversation.