1

The frontent is Next.js, the backend is Django, and we're using the django admin to update information. The info updates just fine on static pages, but on dynamic routes it won't update.

This is what the code looks like on the dynamic route pages on the getStaticPaths and getStaticProps in Next.js:

export async function getStaticPaths() {
 const response = await fetch(
   `${process.env.NEXT_PUBLIC_BASE_CMS}/api/events/all`,
 );

 let events;
 if (response.status === 200) {
   events = await response.json();
 }

 const paths = events?.map((event) => ({
    params: { id: `${event?.id}` },
 }));
  return {
    paths,
    fallback: false,
  };
}

export async function getStaticProps({ params }) {

  const response = await fetch(
    `${process.env.NEXT_PUBLIC_BASE_CMS}/api/events/one/${params.id}`,
  );

  let event;
  if (response.status === 200) {
    event = await response.json();
  }

  return { props: { event: event?.event || null }, revalidate: 10 };
}

I thought adding the 'revalidate:10' would fix the issue, but so far it seems to be continuing, and in order for the changes to show up we have to redeploy every time changes are made to the backend, which isn't ideal.

Any help would be appreciated, thank you!

Kat
  • 11
  • 1
  • Is the issue that existing pages do not update after database changes, or that new paths for the dynamic routes are not being generated? – juliomalves Feb 19 '22 at 16:05
  • @juliomalves both! new paths result in a 404 error, and existing pages do not update after database changes. – Kat Feb 20 '22 at 00:50
  • To solve the 404s on the new paths you should use `fallback: 'blocking'` in `getStaticPaths`, see https://stackoverflow.com/a/66037031/1870780. – juliomalves Feb 20 '22 at 01:35
  • For an existing page to update a new request to that page needs to be made after the `revalidate` period has passed to trigger the regeneration. – juliomalves Feb 20 '22 at 01:37
  • 1
    @juliomalves Thank you so much! I implemented `fallback: 'blocking'` and so far we haven't had any issues! – Kat Feb 24 '22 at 01:54

0 Answers0