the <PrismicRichText /> as well as the <SliceZone /> components from your @prismicio/react package currently throw errors when using them with the latest next.js version and the /app directory.
TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component
I don't want to use the use client option though, as I would like to take advantage of the server side data fetching.
Do you guys have any workaround or are working on a fix already?
Our package supports Next.js 13 when using its traditional pages directory. It does not yet support Next.js 13's beta app directory.
The major version change from v0.1 to v1 was required because of changes to next/image introduced in Next.js 13. We will be working on supporting Next.js 13's app directory soon. No concrete plans or ETA at the moment.
In short, Next.js 13 is not yet fully supported with Prismic, but you can check this thread that might be helpful.
I also fixed it by creating a custom SliceZone component that looks somewhat like this:
/**
* This acts as a wrapper for the actual `<SliceZone />` component from `@prismicio/react`
* Since `<SliceZone />` uses a `createContext`, it will cause issues with next 13 and we don't want to wrap the entire page into the `use client;` option.
*/
"use client";
import { components } from "@/slices";
import { SliceZone as PrismicSliceZone, SliceLike, SliceZoneLike } from "@prismicio/react";
import { FC, memo } from "react";
interface ISliceZone {
slices?: SliceZoneLike<SliceLike<string>>;
}
const SliceZone: FC<ISliceZone> = ({ slices }) => {
return <PrismicSliceZone slices={slices} components={components} />;
};
export default memo(SliceZone);