I seem to have found a bug when using NextJS rewrites in combination with SSR, when also using a catch-all directory path that uses ISR.
The situation: I have a folder in my
/pages directory called
[...pages]/index.js. The page component in that file uses
getStaticProps (in combination with
getStaticPaths) to render every url using ISR. This works like expected on Netlify (and on Vercel).
For specific URLs however, I want to use SSR because I need the query params for that URL. The way I do this is by adding that specific URL as a rewrite to
/render/ssr) and rewriting that to another path that also exists in
/dynamic-pages/[...pages]/index.js). Locally and on Vercel this specific URL renders SSR and I have access to the
context.query. On Netlify however it does seem to render the component in
/dynamic-pages/[...pages]/index.js but I don’t have access to any of the query params. Also when I look in the function logs I see that the logs for this page (which should appear in “Next.js SSR Handler” logs) appear in “Next.js ISR handler” logs.
I have created a demo project that illustrates the problem, you can find the git repository here: GitHub - terrabythia/netlify-rewrite-test: Testing netlify and nextjs rewrites in combination with ISR
I have deployed the project to Netlify and Vercel (exactly the same). When you go to any url you see the (correct) page that says “rendered using ISR” (netlify: https://netlify-rewrite-test-2.netlify.app/any/url, vercel: https://netlify-rewrite-test-eta.vercel.app/any/url). However, when you go to the url that is defined in next.js’ rewrites, you see that the netlify version does not contain any query params (https://netlify-rewrite-test-2.netlify.app/render/ssr?test=true) while the vercel version does (https://netlify-rewrite-test-eta.vercel.app/render/ssr?test=true). And again, the logs for the Netlify page that should be rendered using SSR appear in the ISR function logs.
Can anyone on the Netlify team verify that this is indeed a bug in Netlify?