Error with deployment using parallel intercepted route in Next.js

Reposting this, since I got no answer here and it was automatically closed.

I posted an issue to GH Bug: Parallel intercepted route in Next.js · Issue #11587 · vercel/vercel · GitHub but got redirected here.

I have a Next.js application with a parallel intercepted route. I am catching a certain route and rendering a modal over the current route.
When deployed to Vercel there is an issue when opening that route. The code is working perfectly fine locally in both, development and production mode.

Here is the error I am getting:
Application error: a client-side exception has occurred (see the browser console for more information).

I made a repository with an example: GitHub - Cussone/vercel-nextjs-routing-bug
And here is the deployment: https://vercel-nextjs-routing-bug.vercel.app/en

I found out that on Vercel deployment the page param for the [collection] path gets logged as %5Bcollection%5D inside the modal, which is most likely causing the error. [collection] is the folder name, it should be logging the appropriate part of the path from the URL and not the literal folder name.

If anything else is needed from my side, I will gladly help. Hopefully, I was clear enough.

Thanks for sharing the repo, @cuso! It looks like there’s a typo in the modal path. If you change (..)[collection] with two dots to (.)[collection] with only one dot, that should get it working. I was able to deploy an example that doesn’t get the error by changing only that segment.

I recommend reviewing the Modals section of the Next.js Parallel Routes documentation for the specifics.

Hey @amyegan, thank you for replying!

There is no typo in the modal path. The two dots notation (..) are used to match segments one level above, see the docs for convention.
With one dot the behavior will not be the same. The example I shared works well and as expected when it’s built for production locally, while on Vercel it won’t work the same way and it will throw an error, as explained previously.

You’re right, I made a mistake with my initial test. My example didn’t have the error, but it also didn’t actually have the modal. :person_facepalming:

I took a more careful look this time. The console shows HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Only one element on document allowed which seems to be caused by the directory structure. The intercepting route sits inside the route it intercepts. It works when I change the path from (..)[collection]/[item] to (.)[item]

[locale]/collections/[collection]/@modal/(.)[item] example: https://next-2205.vercel.app

It also works if I modify the project to have the modal route up at a higher level.

[locale]/@modal/collections/[collection]/[item] example: https://next-2205-v2.vercel.app

The intercepting route sits inside the route it intercepts. It works when I change the path from (..)[collection]/[item] to (.)[item]

This works and it will help me with my issue!

However, I still think the previous approach shouldn’t be a problem to build using Vercel if it works well on its own, you guys should file this as a bug.

Thank you for your help @amyegan, it was invaluable!

Have a nice day :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.