vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.72k stars 26.62k forks source link

Incremental Static Regeneration + Fallbacks + Dynamic Route Rewrites with query in URL causes problems #16820

Closed tbgse closed 4 years ago

tbgse commented 4 years ago

Bug report

Describe the bug

This one is a bit tricky and I'm not sure where exactly things go wrong. This might also be a vercel problem rather than next. But here we go:

We have a setup with rewrites looking a bit like this

{
   source: '/:locale/product-name',
   destination: '/:locale/product/product-name'
}

which was not working at all in combination with SSG until a recent change in 9.5.3 (#15231). So far all is working nicely. However, we are running our pages with fallback modes, so they generate static content on the fly. While testing this we noticed that a change in query would not load the cached static file but seem to try and generate another statically rendered version of that same file (curious if this can be disabled / what the reasoning behind this is? mainly because in marketing teams there can be a lot of various queries such as UTM tags etc. being thrown into the urls, so having to go through the render process every time the query is slightly different and display the fallback before the page does not seem ideal at all.

There is another larger problem for us though: When navigating to the source url of the rewrite /:locale/foo the page fails to fetch any json data when a query is present (works fine without a query). I couldn't even see a request in the dev tools for it. This does not seem to be the case for the original url without the rewrite at /:locale/product/foo.

On local I'm seeing this error pop up when trying to navigate to any of these routes with a query:

Unhandled Runtime Error
Error: The provided `as` value (/en/product-name) is incompatible with the `href` value (/[locale]/product/[sku]). Read more: https://err.sh/vercel/next.js/incompatible-href-as

which is an error i've seeing popping up several times already while working with dynamic routes and SSG. I know there have been fixes rolling in for this in 9.5.3 and more coming in 9.5.4 so i guess this is something that is somewhat work in progress?

EDIT: I just managed to make the rewrites correctly work with queries by adding (\\?.*)? to all sources in the rewrite. It still seems to me that there should be an easier way to specify that you want to capture queries for a rewrite or not.

I'm happy to dig in more and set up an example if you can help me point in the right direction where the problem might be and if is something that can be fixed or if this is by design.

We're currently running latest canary (9.5.4-canary.1)

tbgse commented 4 years ago

closing this because it was fixed in the latest canary build. Probably by #16860

balazsorban44 commented 2 years ago

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.