Skip to content

Conversation

@jordanhunt22
Copy link

While doing pagination, if the document at the end of a page was deleted, it would cause pagination to break because we used that document's _id as the cursor. Thus, when the document was deleted, we couldn't find the beginning of the next page since the cursor's _id no longer existed.

I fixed this behavior by using the index keys of the last document in a page as the cursor. That way, if the document is deleted, we can still resume the paginated query at the correct place.

I added tests to confirm this behavior.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 15, 2025

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/convex-test@45

commit: 5d3384e

Copy link
Contributor

@ianmacartney ianmacartney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to dig in later for a deeper review.
At a high level I'd love to re-use some of the work we've done with helpers & paginator that already simulates pagination with user-space cursor keys.
Having this + the helpers + the core implementation feels like a recipe for behavior inconsistency.. but I haven't thought much about how easy it'd be to map the paginator/streams code in here

Comment on lines +388 to +391
if (e instanceof Error && e.message.includes("expected JSON array")) {
throw e;
}
throw new Error("Invalid cursor format: must be a JSON array or null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the user won't be passing in a JSON array - they'll be passing an opaque string and likely will be confused if they see this. Maybe guide them that the cursor needs to be null or a string returned from paginate

@ianmacartney
Copy link
Contributor

ianmacartney commented Jul 18, 2025 via email

Copy link
Contributor

@ianmacartney ianmacartney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jordanhunt22 btw just noticed we never pushed this through

@jordanhunt22
Copy link
Author

@jordanhunt22 btw just noticed we never pushed this through

yeah, unfortunately i think the refactor will take a bit of work. i'll pick this back up when i have some free time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants