Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

How to deploy Gatsby sites using official Sanity starter templates

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.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.

Related topics

Get more help in the community Slack

Go to How to generate RSS.xml files from Sanity posts with gatsby-plugin-feedGo to How to make Algolia work with Gatsby & SanityGo to How to improve image loading with Gatsby and gatsby-plugin-sanity-image?Go to How to Decouple the Kitchen Sink Starter from NetlifyGo to Set up Draft Previews with Gatsby Cloud HostingGo to How to display Sanity images in Gatsby-powered photography sitesGo to Is it possible to use gatsby-image to render images loaded in Portable Text / Rich Text?Go to Deploy a Sanity + Next JS site to Netlify
TopicCategoriesFeaturedRepliesLast Updated
How to generate RSS.xml files from Sanity posts with gatsby-plugin-feed6Jan 12, 2021
How to make Algolia work with Gatsby & Sanity8Jan 7, 2021
How to improve image loading with Gatsby and gatsby-plugin-sanity-image?10Nov 27, 2020
How to Decouple the Kitchen Sink Starter from Netlify8Feb 9, 2021
Set up Draft Previews with Gatsby Cloud Hosting4Aug 26, 2020
How to display Sanity images in Gatsby-powered photography sites19Jun 16, 2020
Is it possible to use gatsby-image to render images loaded in Portable Text / Rich Text?8Jan 1, 2021
Deploy a Sanity + Next JS site to Netlify6Feb 9, 2021

Related contributions

Jamstack Explorers
- Made with Sanity
- has 8 likes

Jamstack Explorers is a free learning platform created by the team at Netlify to chart a course through the amazing offerings in the Jamstack ecosystem

Go to Jamstack Explorers

Occo
- Made with Sanity

Complex product offering with nested product structure and tiered pricing.

Kevin Green
Go to Occo

Figma Config
- Made with Sanity

Website for Config, the global design conference by Figma.

Corey Ward
Go to Figma Config