Starlord
Starlord•4d ago

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;
}
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)}
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)}
5 Replies
Convex Bot
Convex Bot•4d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
ballingt
ballingt•4d ago
hmm could this be React Strict Mode? hm it runs on the backend twice, could it be rerunning because that function accesses auth and the auth changes?
First execution: Gets the initial page of results Second execution: Checks if there are more items after the current page
Ah so you think this might be broken in https://github.com/get-convex/convex-js/blob/main/src/react/use_paginated_query.ts ? Could be!
Starlord
StarlordOP•4d ago
no i double checked everything its usepaginationquery problem
ballingt
ballingt•4d ago
and your proposed behavior would be for it not to do a second check if the first one is exhausted sounds good, want to write the PR? 🙂 this isn't a priority right now since it's not broken (ie the data is correct), but sounds like fixing it is the right thing to do as long as it doesn't make the code much more complicated thanks for letting us know, I've filed this internally. I'd like to fix this, it might be a while. If you've got a pointer on it or a suggested patch it could help it get fixed sooner.
Starlord
StarlordOP•3d ago
ok will look into it. thanks