Nextjs rewrites not applied on SPA navigation

Hello,

I posted a while ago about 404 issues when upgrading @netlify/plugin-nextjs from 5.9.2 to 5.9.3.

Unfortunately I wasn’t able to figure out the issue despite the help and had to put it on hold until now. I was hoping to get lucky and for the issue to be fixed but I also tried the last version of the plugin and the issue is still there.

I finally was able to investigate more and what I see everything is behaving as if my rewrites rules configured in next.config.ts are ignored when requesting a page from the client (the json part) while everything works fine on on a full load of the page (the full html)

The issue can be seen on https://deploy-preview-626--metronautapp.netlify.app/

On that branch I updated @netlify/plugin-nextjs to 5.9.3 (and nextjs to the last version in case it would fix the issue) and what I see is:

  • Any page is loading fine on the first load
  • if I hover a link targeting a page without a rewrite all is fine (discover or catalog for instance)
  • if I hover a link targeting a page with a rewrite I get a 404 on the page.json call (blog which rewrites metronaut-blog to blog)
  • if I click on a rewriten link then I’ll get a full page reload instead of a javascript navigation like expected

So it seems that any page where the route doesn’t match the folder name returns a 404 when trying to get the next data json associated to it.

The old topic in case it might be of use: 404 on all routes when navigating on client side after updating @netlify/plugin-nextjs

Thank you

Can you package this in a minimal reproduction and share the repo so we can check further?

Hello, just a quick update, I’m still trying to have a minimal project that can reproduce the issue. So far there is no issue with a minimal project so I’m adding things little by little when I have some spare time until I figure what’s breaking

Ok I finally found the minmal combo that makes it fails:

  • a rewrite in the next.config.js
  • a middleware
  • @netlify/plugin-nextjs > 5.9.2

I have a public project here : GitHub - mparisot-antescofo/netlify: Test project for netlify rewrites

on the main branch I am using @netlify/plugin-nextjs@5.9.3 and you can see the issue on https://antescofo-test-netlify-rewrites.netlify.app/

On the branch netlify-5.9.2 I went back to using @netlify/plugin-nextjs@5.9.2 and everything is ok as can be seen on https://deploy-preview-1--antescofo-test-netlify-rewrites.netlify.app/

to see the issue, you need to open the dev tools and hover the links. The first one will be ok as there is no rewrite while the second one will trigger a 404 when fetching bad.json

thank you

Hello, @hrishikesh any news on that issue ?

I tried with the latest version of the plugin just in case as I saw one was released a few days ago but unfortunately the issue is stil lthere

Thanks

Sorry for the delay on this one and thank you for the reproduction. I’ve passed it to the devs.