New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ISR in combination with nextjs rewrites not working #2129
Comments
After looking through the other issues I think this is the same issue as this one: #1821 However, I've added a lot of details and steps to reproduce so I think that justifies the "duplicate" issue. |
Unfortunately currently it's not straight forward to handle this out of the box. Part of the problem is rewrite/redirect "stacking" which is currently not supported. We can't create rewrite/redirect the way you define it in next config, instead we would need to know wether target would be SSR or ISR and route to appropriate handler. Creating generic solution for this is not that feasible without rewrite/redirect stacking so instead we are working on stacking support which will allow to support this much easier. The reason query params are stripped (at least in provided repro) is that it is being routed to ISR handler which does strip query params. You can workaround this manually for now by adding following redirects to
( |
Thanks for your response. I don't get your following remark though:
It shouldn't be routed to ISR though right? Because I'm routing it to a SSR page with a rewrite. Or is that because of the limitation of Netlify not having stacking support right now? Your workaround for now does seem to work, thanks! |
I am closing this as the workaround has fixed the issue. We are looking at some changes to support rewrites like this soon. 👍 |
Summary
In a nextjs project when using a catch all directory structure (eg
/pages/[...pages]/index.js
) that uses ISR and combining it with a custom rewrites innext.config.js
using SSR, the SSR page does not work correctly.The ISR pages work correctly, but any pages that are part of a rewrite don't get the URL search params (
context.query
) passed in. Also, looking at Netlify's function logs, the logs that should be under "Next.js SSR Handler" appear under the "Next.js ISR handler", so it looks like there is a problem with the way the page is actually rendered.I have verified that this problem does not occur locally and when deployed on either vercel.com or render.com.
A link to a reproduction repository
https://github.com/terrabythia/netlify-rewrite-test
Expected Result
Expected to see
query
params not set on any URL because the page is rendered using ISR, except for the url/render/ssr
because it's rendered using SSR.Actual Result
Netlify shows no
query
params on the page/render/ssr
and is not actually rendering the page on every load (which is also showing in the function logs).Any URL except the one in the rewrite works correctly on all platforms including Netlify.
Vercel: https://netlify-rewrite-test-eta.vercel.app/any/url
Render: https://netlify-rewrite-test.onrender.com/any/url
Netlify: https://netlify-rewrite-test-2.netlify.app/any/url
The url
/render/ssr
is part of the rewrites innext.config.js
and works correctly on all platforms except Netlify (seequery
params):Vercel: https://netlify-rewrite-test-eta.vercel.app/render/ssr?test=true
Render: https://netlify-rewrite-test.onrender.com/render/ssr?test=true
Netlify: https://netlify-rewrite-test-2.netlify.app/render/ssr?test=true
Steps to reproduce
/pages/[...pages]/index.js
) and usegetStaticProps
to render using ISRnext.config.js
that routes to another page component (eg/pages/ssr/[...pages]/index.js
) which usesgetServerSideProps
to render using SSR.Next Runtime version
13.3.4
Is your issue related to the
app
directory?app
directoryMore information about your build
netlify.toml
)What OS are you using?
None
Your netlify.toml file
No response
Your public/_redirects file
No response
Your
next.config.js
file`next.config.js`
Builds logs (or link to your logs)
Build logs
Function logs
ISR Function logs
(/render/ssr incorrectly gets logged in ISR while it should be rendered using SSR and appear in those logs)
.next JSON files
No response
The text was updated successfully, but these errors were encountered: