0

So at the moment, I have a site I'm creating with Next Js on the front-end with contentful used as my CMS.

I have quite a few pages that use the contentful function to fetch the data:

export async function getStaticProps() {
  const client = createClient({
    space: process.env.NEXT_CONTENTFUL_SPACE_ID,
    accessToken: process.env.NEXT_CONTENTFUL_ACCESS_TOKEN,
  });

  const res = await client.getEntries({ content_type: "MYCONTENT" });

  return {
    props: {
      MYCONTENT: res.items,
    },
  };
}

So imagine this code on about 30 pages. I then filter and map through the items that I need using this code:

{MYCONTNET
            .filter((e) => e.fields.tag === "design tools")
            .map((content) => {              
              return (
                <ToolsCard
                  key={content.fields.title}
                  title={content.fields.title}
                  para={content.fields.tagline}
                  url={content.fields.url}
                  img={content.fields.img.fields.file.url}
                />
              );
            })}

It was going well until I recently came across an issue whereby not all the items get passed to the front end.

My only solution is to republish the content on contentful but when I do it seems to have an effect on the other pages. Even when I tried to console log I cant see the data being passed.

It shows me this image and here is a more detailed image

I'm not sure what the issue is, it was working fine, but when I started adding more content this issue came up.

If anyone can help, that would be great. Thanks in advance.

FamousLastWords
  • 39
  • 2
  • 11
  • 1
    Are you getting any errors in the console or just seeing less data than you should? Could you try and npm run build and see if you get any errors? It also sounds like you might want to consider moving the 'createClient' code to one single place rather than creating e.g. 30 client instances. It might be that you're being rate limited or there are race conditions. – whitep4nth3r Jul 30 '21 at 09:47
  • Hey @whitep4nth3r, I think your right, the issue seems like it might be because of I have the createClient code on all pages. Will look to create that separately. Will let you know if it works. Thanks for the suggestion. – FamousLastWords Jul 30 '21 at 14:17
  • Good luck! Let's hope it works. – whitep4nth3r Jul 30 '21 at 16:12
  • @whitep4nth3r Sorry, but how would you move the createClient code to one place and reference it to other pages? – FamousLastWords Jul 30 '21 at 17:45

1 Answers1

1

Answer:

So I didn't realise, I needed to increase the limit parameter. I had over 113 but the default was 100.

FamousLastWords
  • 39
  • 2
  • 11