๐Ÿ‘€ Our most exciting product launch yet ๐Ÿš€ Join us May 8th for Sanity Connect

Troubleshooting live previews in Next.js project with dynamic loading and React errors.

3 replies
Last updated: Jan 5, 2024
Hi all, I'm having a bit of trouble with live previews in my Next.js project.
I'm trying to avoid duplicating every single component just to have a preview version and a regular one, so instead I made a generic preview component that dynamically loads the correct one and passes it the initial data and the query that it requires.

This kind of works but in preview mode everything flashes (probably due to the dynamic loading logic) and sometimes I get weird React errors saying
A previously unvisited boundary must have exactly one root segment. This is a bug in React.
.
Any suggestions on how to make all this work without weird generic shenanigans and code duplication? Thank you!
Jan 5, 2024, 10:08 AM
๐Ÿ‘‹ We probably canโ€™t help you much without seeing your code.
Jan 5, 2024, 5:05 PM
Yeah, I know but unfortunately I can't share it cause it's for a client and I signed an nda... ๐Ÿ˜…
But I managed to solve my issues by just using the
LiveQuery
component provided by
next-sanity
.
Thanks for the reply!
Jan 5, 2024, 5:10 PM
Oh great! Iโ€™m glad you found a solution.
Jan 5, 2024, 5:11 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?