Request hangs when I use `await params` inside a layout file?
Unanswered
Prothonotary Warbler posted this in #help-forum
Prothonotary WarblerOP
When I use
Here is
await params
inside a layout.tsx file and try to access a page, it just hangs (loads forever). When I just use params without await, I get the nextjs warning about using await to get params.Here is
src/app/[locale]/layout.tsx
import Header from '@/components/header';
import '@/app/globals.css';
import { getDictionary } from '@/lib/dictionary';
import Footer from '@/components/footer';
export default async function RootLayout({
children,
params,
}: {
children: React.ReactNode;
params: { locale: 'ar' | 'en' };
}) {
const locale = (await params).locale;
const dict = getDictionary(locale);
return (
<>
<Header dict={dict} />
{children}
<Footer dict={dict} />
</>
);
}
17 Replies
Chub mackerel
params isn’t a Promise, so await params will hang. You should just access it directly:
const locale = params.locale;
@Chub mackerel params isn’t a Promise, so await params will hang. You should just access it directly:
ts
const locale = params.locale;
Prothonotary WarblerOP
Shouldn't params be awaited?
I used the wrong type. I should've used
but I get the same error.
Btw, the browser keeps loading forever only in development. After building, it works fine
params: Promise<{ locale: 'ar' | 'en' }>;
but I get the same error.
Btw, the browser keeps loading forever only in development. After building, it works fine
@Prothonotary Warbler I used the wrong type. I should've used
ts
params: Promise<{ locale: 'ar' | 'en' }>;
but I get the same error.
Btw, the browser keeps loading forever only in development. After building, it works fine
I think you want to implement the section to change language.
Did you use i18n?
Did you use i18n?
@Jerico Aragon I think you want to implement the section to change language.
Did you use i18n?
Prothonotary WarblerOP
No, I implemented it manually
So does using i18n fix the issue?
@Jerico Aragon 🧐
Prothonotary WarblerOP
Yeah I didn't know about it until I already have implemented it 😅
@Prothonotary Warbler Yeah I didn't know about it until I already have implemented it 😅
What about your middleware?
@Prothonotary Warbler Yeah I didn't know about it until I already have implemented it 😅
First of all, you need to implement the middleware perfectly, and you can get the data.
@Jerico Aragon What about your middleware?
Prothonotary WarblerOP
There's no middleware. I didn't think I need it
Actually, I think I'll implement i18n first then maybe it is fixed. I probably messed up a lot trying to implement it myself
Actually, I think I'll implement i18n first then maybe it is fixed. I probably messed up a lot trying to implement it myself
@Prothonotary Warbler Shouldn't params be awaited?
Chub mackerel
what version of Next did you used?
@Chub mackerel what version of Next did you used?
Prothonotary WarblerOP
v15
Chub mackerel
my bad I guess you using Next v13
@Jerico Aragon No, you need both.
middleware and i18n.
Prothonotary WarblerOP
Just switched to next-intl and there are no issues now. Still do not know what the issue was :D
thank you @Jerico Aragon @Chub mackerel
thank you @Jerico Aragon @Chub mackerel