Preview Not Working for Next.js Project Using SliceZone
See original GitHub issueVersion
- Prismic CLI version (know it by running
prismic --version
): 3.8.3-beta.0
Reproduction
- Create a next.js project configured with slice machine
- Use
SliceZone
component fromnext-slicezone
in a dynamically generated page route - Set up prismic previews
- Deploy to Vercel
- Attempt to preview on deployed site
e.g. pages/[uid].js
:
import SliceZone from "next-slicezone";
import { useGetStaticPaths } from "next-slicezone/hooks";
import Head from "next/head";
import Layout from "../../components/layout";
import { useGetStaticProps } from "../../next-slicezone/hooks";
import { Client } from "../../prismic";
import resolver from "../../sm-resolver.js";
export default function Page(props) {
return (
<Layout>
<Head>
<title>Test Page</title>
</Head>
<SliceZone {...props} resolver={resolver} />
</Layout>
);
}
export const getStaticPaths = useGetStaticPaths({
client: Client(),
formatPath: ({ uid }) => ({ params: { uid } }),
});
export const getStaticProps = useGetStaticProps({
client: Client(),
uid: ({ params }) => params.uid,
});
What is expected?
I should be able to preview a prismic page and see the updated SliceZone
components when deployed to Vercel.
What is actually happening?
The preview works locally, but when deployed the SliceZone
component does not render anything.
Any additional information
The problem seems to lie in useGetStaticProps
from next-slicezone/hooks
. When deployed to Vercel, useGetStaticProps
makes a call to next-slicezone/features/registry.js
, and Vercel cannot find the config file here.
When deployed, pathToSmFile
is /var/task/sm.json
, which doesn’t seem to exist when Preview mode is used. So the props passed to my SliceZone
component don’t include any registries.
useGetStaticProps
is behaving as expected when not using Preview.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (2 by maintainers)
Top Results From Across the Web
next-slicezone Technical Reference - Documentation - Prismic
Learn how to work with Slice Machine's next-slicezone to render Slices, query documents, and build routes.
Read more >Creating a Project With Slice Machine & Next.js - YouTube
Today Alex is presenting how to set up Slice Machine with Next. js in order to start developing slices - website sections -...
Read more >Next.js 13 and Prismic Slice Machine - YouTube
Alex Trost from the Prismic.io team is joining to take a hands-on approach to trying out Prismic Slice Machine in a Next. js...
Read more >next-slicezone - npm
SliceZone (wip). A component that matches front-end components with Prismic slices. Pretty much a work in progress, README coming. RFC: https:// ...
Read more >Next JS error with linking between dynamic pages of a ...
I'm having some trouble with a dynamic route in Next JS, ... to any other project page from the home or work pages,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the detailed report! I believe this would require a rewrite, let me talk about it with the team tomorrow and see how we can tackle it
Alright, who wants to try
next-slicezone@0.0.12-alpha.0
? 😊The only change to your code it requires would be to add a condition on when the resolver is being called in
pages/_document
. Mine is like this at the moment:Hope that helps. Let me know!