Next.js Discord

Discord Forum

Fetch Loop for static generated page

Unanswered
Green-tailed Towhee posted this in #help-forum
Open in Discord
Green-tailed TowheeOP
generated this /locale/products/:id -> during the build time using the generateStaticParams
But when I visit the page , I see way too many get request on same page/product , anyone got any idea , what would be the cause for this ?

My Code :
ts 
 export async function generateStaticParams() {
    const products = await prisma.product.findMany({});
    const locales = ["en", "ar"];
    const paths: { id: string; locale: string }[] = [];
    products.map((prod) => {
        locales.forEach((locale) => {
            paths.push({ locale, id: prod.id });
        });
    });

    return paths;
}

export async function generateMetadata({
    params: { id, locale },
}: {
    params: { id: string; locale: string };
}) {
    const product = await prisma.product.findFirst({
        where: { id },
        include: { category: true },
    });

    return {
        title: locale === "en" ? product?.title : product?.ar_title,
    };
}

const page = async ({ params }: { params: { id: string; locale: string } }) => {
    const locale = params.locale;
    unstable_setRequestLocale(locale);
    const product = await prisma.product.findFirst({
        where: { id: params.id },
        include: { category: true },
    });

    if (!product) {
        return <div>Not Found Page</div>;
    }
return <div>singleproduct</div>
 

0 Replies