Prismic API - pageSize not working

Hello,

I'm currently working on a project with NextJs + Prismic, where I need to get only a small amount of documents (for performance reasons) and I tried to use the pageSize parameter but it seems like it doesn't work. It's set to pageSize=3 but it always returns all the documents.

I've also searched for similar issues and it seems like other users had problems with it too.

Here is the query:

   await client.getAllByType("blog_post", {
        fetchLinks: ['author.name', 'author.avatar', 'author.position'],
        pageSize: 3
    });

Thanks for your help!

Hello @gabriel.cioci

Welcome to the Prismic community and thanks for reaching out to us.

pageSize parameters should return 3 documents if it's set so. I can not recreate the issue with my repository. If you can send me your repo URL I'll check with it(You can send me a private message though)

Thanks,
Priyanka

Hello Priyanka, I've sent the repo URL as a pm, can you take a look?

Thanks

Hello @gabriel.cioci

I have sent you a private message.

Thanks,
Priyanka

Hi Priyanka,
Do you mind sharing the solution here?
I am experiencing the same issue.
Cheers,
Mike

Hello @moorenmike, the team suggests two options:

1. getAllByType() with limit:
getAllByType() will fetch all documents. To limit the number of documents returned, the limit option can be passed. Once the function reaches that limit, it will stop requesting pages.

await client.getAllByType('page', { limit: 3 })

2. getByType() with pageSize:
getByType() only fetches one page, thus pageSize will limit the results to the size of that single page. The response will include the pagination metadata along with the data using this method, however, so you’ll need to access the results using res.results.

await client.getByType('page', { pageSize: 1 })
1 Like