I’m trying to generate dynamic metadata using the built-in Next.js method generateMetadata. On localhost, it works: it fetches the title, reads the related article, and generates the metadata in the <head> tag.
However, when I deploy to my development environment, I get the well-known infinite loading issue in Next.js 14. I have tried every existing fix. Everything works locally but nothing works on the dev environment.
Here is the folder structure:
/article
/[title]
page.tsx
articleContent.tsx
layout.txt
page.tsx
I read that having a parent layout should not interfere with generateMetadata. I even tried removing it, and it still doesn’t work.
/article/layout.tsx
export const metadata: Metadata = {
title: "...",
description: "...",
};
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="fr">
<head>
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap"
rel="stylesheet"
/>
</head>
<body>
<ToastProvider />
{children}
</body>
</html>
);
}
/article/[title]/page.tsx
type Props = {
params: Promise<{ title: string }>;
};
export async function generateMetadata({ params }: Props, parent: ResolvingMetadata): Promise<Metadata> {
const { title } = await params;
const article = await NewspaperService.assetNewspaperArticleRead(1);
return {
title: "Article",
description: "Article Hacker ouvert.",
};
}
export default async function Page({ params }: Props) {
const { title } = await params;
return
}
As you can see, this method is very simple and simplified for the example. I noticed that the infinite loading is caused by the line:
const article = await NewspaperService.assetNewspaperArticleRead(1); const article = await NewspaperService.assetNewspaperArticleRead(1);
But according to the official documentation, async calls should no longer cause infinite loading.
For this example, the Page function returns nothing, but that doesn’t really matter because it never gets reached anyway.