最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

next.js - ISR for dynamic route with ORM not working in nextJS - Stack Overflow

programmeradmin0浏览0评论

I have few categories pages for which I am not able to generate static pages with all the data.

I have tried to cache the result from prisma

const getProducts = cache(async ({color, theme, orientation, productCategory, limit}:{productCategory: ProductCategory, color: ProductColor,theme?: Theme, orientation: DesignOrientation, limit: number }) => {
  return await ServerActionFetchProductsForProductCategory({
    color,
    theme,
    orientation,
    productCategory,
    limit,
    page: 1,
  });
});

I am also generating static pages during build. Which is working correctly. i.e. all categories pages are bring build.

export async function generateStaticParams(){
 
  return Object.values(Theme).map((theme) => {
    return {
        themeSlug: ThemeUtils.getThemeAttributes(theme).slug,
    };
  });
}

But when I load the page, it send the category page with loading state and not the page with data from prisma. It loads the data afterwards.

My page:

export default async function page({
  searchParams,
  params,
}: {
  searchParams: { [key: string]: string | string[] | undefined };
  params: params;
}) {

const limit = 10;
  const seoComponent = new SeoCategoryPageComponent();
  const color = searchParams.color as ProductColor;
  const orientation = searchParams.orientation as DesignOrientation;
  const theme = ThemeUtils.getThemeAttributesBySlug(params.themeSlug).theme;
  const page =
    (searchParams.page as string) == '' ? 0 : (searchParams.page as string);
  const { products } = await getProducts({
    color,
    theme,
    orientation,
    productCategory,
    limit,
  });

return (
    <>
        <ProductCategoryList
         initialProducts={products}
         header={
           ProductCategoryUtils.getProductCategoryAttributes(productCategory)
             .title
         }
         theme={theme}
         limit={limit}
         searchParamsColor={color}
         searchParamsOrientation={orientation}
         searchParamsTheme={theme}
         breadcrumbs={getBreadcrumbs({
           productCategory,
         })}
         seoDescription={getSeoData(productCategory).general}
         productCategory={productCategory}
       />
    </>
  );
}

If I remove await keyword from the category page, then ISR is correctly built and loading screen is not displayed but if I keep the await keyword then ISR although gets generated during build but loading state is present in the file (instead of data) and it get all the record afterwards.

发布评论

评论列表(0)

  1. 暂无评论