-
Notifications
You must be signed in to change notification settings - Fork 64
Description
In this discord thread (https://discord.com/channels/1019350475847499849/1385358143437017178) I surfaced a problem I was having whereby using the filter helper on a query thats paginated will miss results when doing a simple string filter.
Given a query like this:
export const paginate = query({
args: {
paginationOpts: paginationOptsValidator,
searchTerm: v.optional(v.string()),
},
handler: async (ctx, args) => {
const term = args.searchTerm?.toLowerCase();
return filter(ctx.db.query("users"), (user) => {
return term ? user.name.toLowerCase().includes(term) : true;
})
.order("asc")
.paginate(args.paginationOpts);
},
});
And a callsite like this:
export default function Home() {
const [searchTerm, setSearchTerm] = useState("");
const term = searchTerm === "" ? undefined : searchTerm;
const { results: users, isLoading } = usePaginatedQuery(
api.queries.paginate,
{
searchTerm: term,
},
{ initialNumItems: 10 }
);
...
}
Versions:
"dependencies": {
"convex": "^1.29.3",
"convex-helpers": "^0.1.106"
}
When I search for a user thats not on the first page, it never seems to find a result. I have seeded 50 users, showing 10 for the initial page size. If I search for anyone thats not on the first page, but is definitely in the data, I can never find them.
Reproduction repo:
https://github.com/willemclarke/convex-filters-pagination-reproduction
Steps:
git clonebun installornpm installnpx convex devnpx convex import --table users sampleUsers.jsonlbun devornpm run dev- Search for "Kevin White" or anyone below "Julia Jackson" in the
sampleUsers.jsonlfile -> it should not find them.
Now I really want to apologise if I'm blatantly mis-configuring anything here, but I essentially took this code from https://stack.convex.dev/complex-filters-in-convex#escape-hatch-pagination. Any help is appreciated.