Next.js Discord

Discord Forum

Middleware Issues in Vercel Deployment: Multiple Requests for All Pages

Unanswered
Andalusian Hound posted this in #help-forum
Open in Discord
Avatar
Andalusian HoundOP
In the project I deployed on Vercel, my Next.js version is 14^. When I build and test it locally, the middleware works correctly. However, when I check the Vercel runtime logs, I see that when a user is redirected to a page, requests are made for all pages. What could be causing this, and how can I resolve it? Thank you in advance.

2 Replies

Avatar
Andalusian HoundOP
Image
Avatar
Southern yellowjacket
Did you find an answer to your question? I am currently seeing the same behaviour. I think it has something to do with the Link component. The Link component prefetches the page when the link enters the user's viewport (initially or through scroll). Next.js prefetches loads the linked route and its data in the background to improve the performance of client side navigations. Prefetching is only enabled on production. I think this is why we see the middleware being called for so many pages in the logs.