Hey everyone!
I've recently switched to the new Next.js Starter Pack (with server actions) and have noticed my site running significantly slower than the previous one. I suspect there might be an issue with the Next.js caching system (https://nextjs.org/docs/app/building-your-application/caching). For instance, in local development, my category page load is generating 2 API calls (one for the metadata and one for the page), whereas, if I understand the Next.js documentation correctly, it should only be making one call due to caching and the Next.js tags mecanism.
// src/app/categories/[handle]/page.tsx
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const category = await getCategoryByHandle(params.handle)
if (!category) {
notFound()
}
const metadata = {
title: `${category.name}`,
description: `${category.description}`,
} as Metadata
return metadata
}
export default async function CategoryPage({ params }: Props) {
const category = await getCategoryByHandle(params.handle)
if (!category) {
notFound()
}
return <CategoryTemplate category={category} />
}
export const getCategoryByHandle = cache(async function (
handle: string
): Promise<ProductCategory> {
const category = await medusaClient.productCategories
.list({ handle: handle }, { next: { tags: ['categories'] } })
.then(({ product_categories }) => product_categories[0])
.catch((err) => {
throw err
})
return category
})
What are your thoughts on this? Has anyone else experienced similar issues or have any insights on how to resolve this caching problem? Appreciate any help or advice you can provide!