Next.js Discord

Discord Forum

Root layout somehow running twice

Unanswered
GetPsyched posted this in #help-forum
Open in Discord
I have a middleware for localisation which is identical to the default [here](https://nextjs.org/docs/app/building-your-application/routing/internationalization).

After some spamming logs debugging, I've found that the middleware runs once on /, appends the locale and then the root layout.tsx runs twice, one where params is undefined and one where it is { lang: 'en' }. The webpage loads fine because of this, but I get an error in my server console because it is undefined.

12 Replies

Hmm, seems like the middleware has nothing to do with this, layout.tsx is being called twice either way
Blackpoll Warbler
Could be due to development environment, have you tried checking the logs in deployment if you are logging something from the root layout?
in production?
Okay this is a serious problem
It's causing my intercepted route to break as well
The modal opens but with my fallback not found behind it
Which is presumably from the naive /search route
Which the middleware should've caught and not redirected
Okay hmm, this is happening even if I avoid the middleware
Feels like a bug in nextjs tbh
@GetPsyched The modal opens but with my fallback not found behind it
Okay I bumped the nextjs version and this got fixed