prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

Can't render rich text in nextjs server component #175

Closed justin-hackin closed 12 months ago

justin-hackin commented 1 year ago

Previously, I was using

"prismic-javascript": "3.0.2",
"prismic-reactjs": "1.3.4",

to render rich text fields in a next.js server component and I decided to upgrade. I don't need slices, I just want to get my data into a single component and pass it down through props. Previously I was able to render them just fine using RichText.

I migrated to

    "@prismicio/client": "6.7.3",
    "@prismicio/helpers": "2.3.9",
    "@prismicio/react": "2.5.1",

Now the app barks at me for trying to use a context in a server component 😖 with

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

Is it possible to use this component without a context in a server component or do I have to revert to the old versions of this library?

angeloashmore commented 12 months ago

Hi @justin-hackin, React Server Components and Next.js' App Router is a significant change from pre-Next.js 13.4. The update required changes in how <PrismicRichText> works and, in some cases, how it is used.

I just published v2.6.0 which now supports Server Components. See #178 for more details.

You should be able to use <PrismicRichText> in Server Components now. 🙂