medusajs / nextjs-starter-medusa

A performant frontend ecommerce starter template with Next.js 14 and Medusa.
https://next.medusajs.com/
MIT License
1.78k stars 497 forks source link

Fix: ensure valid pageParam to prevent negative offset in pagination #371

Closed Mohmdev closed 1 week ago

Mohmdev commented 1 month ago

Fixes #9432

This PR fixes the bug in product pagination by ensuring that pageParam is always valid (i.e., greater than or equal to 1) before calculating the offset. It prevents negative values from being passed to the offset, which was causing a runtime error.

Fix Details: Instead of just removing -1 from the offset calculation, I used Math.max(1, pageParam) to guarantee that pageParam will always be at least 1. This ensures that the offset calculation is never negative while keeping the existing logic intact.

vercel[bot] commented 1 month ago

@MohmDev is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

VariableVic commented 1 week ago

Thanks! This was solved in #370, closing this now.