StarlordS
Convex Community13mo ago
11 replies
Starlord

pagination query 2 server requests on start

hello. please explain why paginated query is executing 2 times on first execution even it is exhausted?

it think the problem is with convex source code:
First execution: Gets the initial page of results
Second execution: Checks if there are more items after the current page

its doing second request even if first is already 'Exhausted'


export default function NewProductPage() {
  const result = usePaginatedQuery(
    api.admin.listOwnPendingProducts,
    {},
    { initialNumItems: 10 }
  );      

  useEffect(() => {
    console.log('Query state changed:', {
      status: result.status,
      productsLength: result.results?.length,
      isLoading: result.isLoading,
      results: result.results
    });
  }, [result]);

  return null;
}


Query state changed: {status: 'LoadingFirstPage', productsLength: 0, isLoading: true, results: Array(0)}
Query state changed: {status: 'LoadingFirstPage', productsLength: 0, isLoading: true, results: Array(0)}
eruda.js?v=374bd0d1:3361 [CONVEX Q(admin:listOwnPendingProducts)] [LOG] 'listOwnPendingProducts executed on backend'
Query state changed: {status: 'Exhausted', productsLength: 1, isLoading: false, results: Array(1)}
eruda.js?v=374bd0d1:3361 [CONVEX Q(admin:listOwnPendingProducts)] [LOG] 'listOwnPendingProducts executed on backend'
Query state changed: {status: 'Exhausted', productsLength: 1, isLoading: false, results: Array(1)}
Was this page helpful?