I'm playing with Prismic on a small project before going full production and I'm hitting a wall .
I started from a mix between the NextJS Blog and the NextJS i18n example. Locally using yarn dev and or yarn build && yarn start, everything works like a breeze.
But when I send everything on Vercel:
any client-side routing to, say, my "blog" page, will fail with a An unexpected error has occurred. message.
any server-side routing (page refreshing, direct link) will display a mostly-empty page (just my Layout, and nothing inside it).
Did I missed something obvious? Any help is appreciated. Thanks
I added some logs here and there... It seems my posts params I pass to my Page component is undefined... What could cause this and what would be the best way to debug this? I'll try to add some try/catch around my prismic call.
After some more tests, it appears it's related to the fact that I had a dynamic, statically generated page at the same level. I'm not sure if it's related to NextJS or Prismic.
Here is the faulty structure :
pages
_app.js
[uid].js
mypage.js
Here, mypage.js is not rendered correctly. If I switch to SSR, it works.
This line seems a little strange, I'm not sure why you would pass the locale and ref together. In the example you shared, you've already opened the options object and each option should be on a new line.
What you did makes sense here for example where they are both passed as options together:
In my prismic repo, I created a "Test" page (uid: test), with a simple content "Hello".
The test.js file is a copy of the index.js + some debug info.
If you go on the homepage, everything works fine. If you go on the /test page, only the doc renders. If you use the link at the bottom of the index page, then you are redirected to another version of the page which is broken...
It looks like a race condition between [uid].js and test.js somehow, when a page with such an uid exists... But in a classic NextJS fashion, the test.js should have precedence over the catchall route.
Again, thanks for your time Phil! I really appreciate this.
So I had a look at your project and indeed test.js is generated on the live website and [uid].js with the uid of test is shown locally. I'm not sure why it's doing this, though seems like this is more an issue with how Next.js creates its statically generated routes.
The link at the bottom of the page uses the link resolver so it's search for a page type with the uid: test, this works on local since it's there, but breaks on the live site since it doesn't exist.
But like you said:
So it's working correctly on the live website.
What's the use case here for having 2 routes with the same name?
I didn't have any clear use case in mind. My mental model was the following: "I have a foo.js page, so my uid.js won't bother with any "foo" path." So yeah maybe it's just an edge case here. Should we add somewhere in the doc that catchall route + static route "can" technically coexist (in a NextJS fashion) but should not be used with Prismic ?
I'm not really sure that this is something that should be in our documentation, I feel it's something that's explained in Next.js:
Yes locally it might be possible to see it, but really on a live website, the correct behavior of predefined routes taking precedence over dynamic routes exists. So yeah maybe a note for some users of what to expect on a live website and with a link to the page above would be useful. What do you think?
IMHO that should do the trick. At least people will be redirected to the NextJS doc and will have a closer look on routing precedence. Is there a place I can submit a PR ? Or can you do it ?