Live Preview with Next.js
Written by Knut Melvær
Today, we're introducing live content authoring previews for Sanity-powered Next.js sites. The fastest, most lightweight preview experience: available today in our new toolkit for Next.js.
Launch one of our new starters on Vercel to give it a quick try, or enjoy the details below. The preview runs entirely client-side, so there's no need to set up special servers or other infrastructure: it just works, right in the browser.
Deploy an e-commerce Next.js starter with live preview →
Jamstack and static sites work great for people on the web. But as always, there are tradeoffs. Even with incremental builds and other optimizations, you may introduce latency from pushed publish until you see changes manifest on your site. Thanks to Next.js’ fallback mode, you can selectively render new content on the fly, but even a page refresh feels long when you are in a creative flow. It also doesn’t play well in collaborative settings or when there’s a lot of connected data changing.
Sanity is built for real-time collaboration from the ground up. The open-source Sanity Studio brings features like Presence to let you see where your team is working when you're in the same document, and Review Changes let you inspect and selectively revert any change made to a document. The Split Pane feature gives you a way to extend the editorial experience with custom previews, with APIs for leveraging the real-time content in the Studio.
Thanks to our open-source technologies like groq-js and Mendoza, we are able to mimic a part of our real-time datastore in the browser. We baked this into the new toolkit for Next.js to let you use the same GROQ expression to fetch data from the backend, to also subscribe to changes when you're authenticated (logged into your Sanity project). Practically, this is exposed as a React Hook that you use in your page template to update the page data coming in from the Next.js data fetching methods.
Internal server error