Next.js Discord

Discord Forum

Pagination with Server Components broken

Unanswered
Savannah posted this in #help-forum
Open in Discord
SavannahOP
<div className="flex mt-2 mb-4 gap-x-2">
        {Array.from({ length: Math.ceil(count / limit) }).map((_, i) => (
          <Link
            href={{
              pathname: "/",
              query: { ...searchParams, page: i + 1 },
            }}
            key={i}
          >
            {i + 1}
          </Link>
        ))}
      </div>


export default async ({ searchParams }) => {
  const { page = 1, username } = searchParams;
  const { data, count } = await getData(page, username);
}


I'm using this to get pagination but it looks like it only works in dev and not production on Vercel?

In production, clicking the links do not change the searchParams so I don't get the relevant data.

Looks like it works if I swap Link with useRouter.push (even without .refresh). How come?

4 Replies

SavannahOP
pls help
Bengal
Have you tried disabling prefetch?
@Bengal Have you tried disabling prefetch?
SavannahOP
is there a reason this would cause problems with pagination on the same page?
but i will try it