prismicio / prismic-next

Helpers to integrate Prismic into Next.js apps
https://prismic.io/docs/technologies/nextjs
Apache License 2.0
57 stars 7 forks source link

NextRouter was not mounted error using PrismicPreview #57

Closed MKlblangenois closed 1 year ago

MKlblangenois commented 1 year ago

Versions

Reproduction

When I'm trying to add <PrismicPreview /> inside my page, I got an error from NextJS

Additional Details
Code used : ```tsx // ./app/layout.tsx "use client"; import { PrismicProvider } from "@prismicio/react"; import Link from "next/link"; interface RootLayoutProps { children: React.ReactNode; } const RootLayout: React.FC = ({ children }) => { return ( } >
{children}
); }; export default RootLayout; ``` ```tsx // ./app/page.tsx "use client"; import { PrismicPreview } from "@prismicio/next"; import { repositoryName } from "../library/prismic"; const Page = () => { return (

Hello world!

); }; export default Page; ```

What is actually happening?

Got an error from NextJS : Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted.

Possible way to fix that

When I look to vercel/next.js#43585, It seems like replace next/router by next/navigation (used inside PrismicPreview.tsx on line :58 for useRouter) can solve this issue.

github-actions[bot] commented 1 year ago

This issue has been labeled as a bug since it was created using the 🚨 Bug Report Template.

Hi there, thank you so much for the report!

Following our Maintenance Process, we will review your bug report and get back to you next Wednesday. To ensure a smooth review of your issue and avoid unnecessary delays, please make sure your issue includes the following:

If you have identified the cause of the bug described in your report and know how to fix it, you're more than welcome to open a pull request address it. Check out our quick start guide for a simple contribution process.

If you think your issue is a question (not a bug) and would like quicker support, please close this issue and forward it to an appropriate section on our community forum: https://community.prismic.io

- The Prismic Open-Source Team

angeloashmore commented 1 year ago

Hi @MKlblangenois, thanks for the report!

@prismicio/next does not support Next.js's beta app directory at this time. We are waiting for the feature to stabilize before supporting it since it will require significant changes to the package.

You can find more details about this decision here: https://github.com/prismicio/prismic-next/pull/48#issuecomment-1316270169

Since that comment was written, Next.js's app directory feature has improved, but we prefer waiting until it is more mature.

If you have any questions, please let us know! 🙂