Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Understanding how to trigger Gatsby builds with Sanity Studio updates

24 replies
Last updated: Nov 30, 2020
Hello!
Recently started to play with sanity and gatsby.js for a new project I want to work on. On your site I noticed that you have a few templates up with next.js and gatsby for ecommerce/blog sites. I set up the gatsby template and deployed it and everything but I can seem to understand why when I update data in the Studio, the only way to update data on the front-end is to redeploy. Is this supposed to be happening? Or should it update dynamically. I know its using SSR but I thought that there would be some sort of "incremental static regeneration".

Sorry if this is a bad question, I'm just really having trouble understanding.
Nov 30, 2020, 2:18 AM
I think you’re asking why it doesn’t build automatically when you update content? In that case, you need to set it up to trigger a build when you publish content in the studio. It’s in manage.sanity.io in settings > API > Add new webhook, you get the webhook from Netlify and copy/paste it there.
If that’s not what you mean then disregard
Nov 30, 2020, 2:50 AM
Yes, thank you for the response! I managed to add the webhook to the API settings, but it still doesn't trigger a new build when I publish something new.
Nov 30, 2020, 4:43 AM
You’re publishing from the actual studio, not a local server setup? And you grabbed the webhook from the Gatsby frontend, not the studio?
Nov 30, 2020, 4:47 AM
It’s the frontend that needs to re-build for the changes to display
Nov 30, 2020, 4:47 AM
Yeah, I was getting the hook from netlify, for some reason it keeps rebuilding the studio and not the front-end
Nov 30, 2020, 4:48 AM
and yes--not local server
Nov 30, 2020, 4:49 AM
Are you sure you set up the webhook on the Gatsby build? I haven’t used the Gatsby starter, I use 11ty, but if I’m not mistaken they both deploy two Netlify builds one for the frontend one for the studio. It sounds like maybe you set up the webhook on the studio build? If that’s not it I’m not sure
Nov 30, 2020, 4:51 AM
Yeah--I got it to work , it was my fault, grabbed the wrong webhook
Nov 30, 2020, 4:53 AM
however, it still takes forever to rebuild
Nov 30, 2020, 4:53 AM
I did exactly the same thing when I set mine up for the first time. 😂
Nov 30, 2020, 4:55 AM
😂
Nov 30, 2020, 4:55 AM
It does that when it’s waiting for another build to finish
Nov 30, 2020, 4:58 AM
got it, yeah is it supposed to take a while to re-deploy? or is there any way to get quicker updates through this approach?
Nov 30, 2020, 4:59 AM
There are different things you can do to minimize build time, but in general it’s going to take a couple minutes for smaller sites. I’ve heard of larger sites taking quite a lot of time to build.
Nov 30, 2020, 5:02 AM
Once your site scales to the point where build time is a real issue, you can split it into smaller micro-sites so that only the parts you update are re-built (for instance, separating a site’s blog and store). Netlify’s free tier is 300 build minutes per month, I’ve yet to exceed that running two smaller sites
Nov 30, 2020, 5:04 AM
ah okay, makes sense. my usecase is an eCommerce website, but taking into consideration, every time an item is bought it would have to redeploy to update quantity on an item?
Nov 30, 2020, 5:06 AM
I don't think waiting for it to rebuild for 2 minutes will work, unless I'm thinking of it completely wrong.
Nov 30, 2020, 5:06 AM
I haven’t yet built an eCommerce app with jamstack so I’m not 100% sure how it works, but I think that’s handled by whichever API is running your store. Again I’m not 100%, don’t want to give you bad info
Nov 30, 2020, 5:09 AM
Got it, no problem. I appreciate your help otherwise!
Nov 30, 2020, 5:10 AM
Of course! This slack channel has helped me a whole lot so I try to pay it forward whenever possible. 😁
Nov 30, 2020, 5:11 AM
Re: build time, you might want to check into Gatsby Cloud and incremental builds (can also make it work on Netlify). https://www.netlify.com/blog/2020/04/23/enable-gatsby-incremental-builds-on-netlify/
Also, check if the build script clears the cache and that you also check in package-lock files so it doesn't need to reinstall all that stuff everytime.
Nov 30, 2020, 12:38 PM
Some data is simply too dynamic, and it no longer makes sense to generate static sites for it. "Items left in stock" is probably a good example (unless you stock something that sells very rarely..)
You should probably go for an API-type solution
🙂
Nov 30, 2020, 12:44 PM
You may want to watch how Prima.co was made: https://www.youtube.com/watch?v=_Vc08kO7qmQ

user G
goes over a fair amount of details on how it was put together and the considerations needed.
Nov 30, 2020, 1:45 PM
Awesome, thank you all for the replies! I really appreciate it.
Nov 30, 2020, 8:59 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?