Next.js Discord

Discord Forum

Simple Route change triggers the middleware 5 times with the same path

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
Hello,
I am currently developing an app and its running with nextjs 13.5.4. Recently I noticed that my app triggers the middleware 5 times with just a simple route change from /dashboard to /products/search. The console log you see here is console.log('path', req.nextUrl.pathname)

On every window focus and on every route change, its triggering the middleware 5 and sometimes 6 times with the same pathname all the time.

I have no clue why that is the case, my matcher excludes images etc, otherwise you would see here other paths. I can not find out why that is the case.

Maybe someone has an idea? I am at a point where I have no more ideas. Been checking this for a while now and I have no idea

The big issue behind is that every middleware trigger triggers also the supabase auth getSession to check for the session / refresh it. This causes supabase to run into a rate limit as its calling the getSession() too often.

2 Replies

Asiatic LionOP
I have noticed that there are quite a few github issues about it https://github.com/vercel/next.js/issues/39917
Asiatic LionOP
bump