Register now - Learn how Tecovas roped in success with Sanity and Shopify 🤠

Issue with updating content in Next.js site hosted with Sanity

8 replies
Last updated: Apr 23, 2021
Hey so this might be a weird question but this is the first time im hosting stuff myself so im kinda lost, I finished my project which was a nextjs site with sanity to handle content etc. i wanna host them myself so i ran
sanity build public
next build && next export
and then got it up and running.. but my issue is that my site isnt getting the new content if i update it in the studio.. e.g changing the hero image or something.. idk if im missing something obvious or if im doing something wrong.. It seems to be doing all the requests at load but yeah idk
Apr 22, 2021, 10:23 PM
Hi User. It will depend on how you’re fetching your data in Next, but it sounds like you’re using static generation (
). That’s fine, but will mean either building every time you want to refresh the data on your site or using something like incremental static regeneration to re-render your pages. Alternatively, you could use server-side generation (
Each has its advantages and drawbacks. I’m a big fan of ISR but you’ll want to make the choice that’s best for you. See
this page for more details and of course, post back here if you face any struggles.
Apr 22, 2021, 10:56 PM
Building as in using sanity build public every time data is updated?
Apr 23, 2021, 8:03 AM
Hmm, i tried changing to
but that doesnt work if you’re exporting to a static page, i also initially had
in my
return to make it refetch the data if there was any changes but that evidently didnt work..
Apr 23, 2021, 3:48 PM
If you don’t want to write a loading component, you could set
fallback: 'blocking'
in your return from getStaticPaths. You would use that in conjunction with getStaticProps with
revalidate: <num>
in the return.
Apr 23, 2021, 3:52 PM
Hmm how would that change the issue that its not fetching other than when i do the initial build, e.g
next build && next export
Apr 23, 2021, 3:54 PM
This is what my
looks like for my posts (excluding the component itself):

export async function getStaticProps({ params }) {
  const post = await getPostBySlug(params.slug);

  return {
    props: { post },
    revalidate: 60,

export async function getStaticPaths() {
  const allPosts = await client.fetch(`*[_type == "post"] | order(date desc, _updatedAt desc) {
    'slug': slug.current,

  const paths = allPosts?.map((post) => ({
    params: { slug: post.slug },

  return {
    fallback: 'blocking',
Apr 23, 2021, 3:54 PM
Hmm how would that change the issue that its not fetching other than when i do the initial build, e.g 
next build && next export
That’s the gist of ISR. When someone visits a slug that doesn’t exist, it builds it. It’s using blocking so you probably wouldn’t want to have a site user have to wait on it, so what I do it visit the page after I create a post and then it does the incremental build.
Apr 23, 2021, 3:56 PM
hmm fair enough, i’ll give it a try 🙂
Apr 23, 2021, 3:57 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?