0

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.

1 Answer 1

0

Async generate Metadata with await calls in Next.js 14-15 can cause infinite loading, especially in environments other than localhost.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank's for the quick answer, I think i partially found the problem, when fetching on my dev API in dev env, this doesn't work. But when i fetch de prod API it works ! I'm just giving up on dev and pushing in prod ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.