👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Help with implementing Sanity in Next.js site and resolving issues with new content not automatically appearing.

11 replies
Last updated: Sep 29, 2023
Hi folks.. I need your help with my Sanity implementation to my Next.js site. New published Sanity content is visible on my Next.js site only if I change something in the API call, such as
apiVersion
, so it is not hapenning automaticly as it should.
Sep 29, 2023, 12:29 PM
that's a next js problem. I had to set every query to no-cache and adding
export const dynamic = 'force-dynamic';
to every page.
I am aware that this is terrible solution. I wonder if anyone else has a better way to solve this
😅
Sep 29, 2023, 12:32 PM
unless you are not using app dir. Then you could set revalidate in your
getStaticProps()
Sep 29, 2023, 12:33 PM
I am quite new to all this, so I don´t know how exactly to make these steps, but at least now I know what should I be looking for.. Thank you very much
Sep 29, 2023, 12:36 PM
join NextJs discord server. You can find more help regarding Nextjs spesific things there 😊
Sep 29, 2023, 12:38 PM
I am using app dir, but I dont thing I am using
getStaticProps()
.. I was following this tutorial https://www.youtube.com/watch?v=OcTPaUfay5I and I understood taht you dont need that for this in Next.js 13
Sep 29, 2023, 12:41 PM
try adding this anywhere in the (dynamic) page
export const revalidate = 10
Sep 29, 2023, 12:58 PM
yeah, no with app dir you don't need
getStaticProps
cause app dir handles server side a bit differently.
Sep 29, 2023, 12:59 PM
To clarify
user U
, the
app
and
pages
directories on Next.js will handle things differently, including fetching data. It seems your issue can be solved by the solutions above, but please make a new message if it doesn't, letting us know which Next.js version you're using, as well as which router (
app
or
pages
). Thanks!
Sep 29, 2023, 1:19 PM
I am using Next.js v13.5.3 and it seems that solutions above helped me. I am using app directory and I used every suggestion 🙂• I added
{ cache: 'no-store' }
at the end of every of my Sanity fetch• I added
export const revalidate = 10;
and
export const dynamic = 'force-dynamic';
to my every page.tsx and layout.tsx
Sep 29, 2023, 1:26 PM
It is not superfast.. I have to wait a few seconds, but it is working.. Thank you very much everyone
Sep 29, 2023, 1:27 PM
Glad to hear it's sorted!
Sep 29, 2023, 1:51 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?