Closed odwrotnie closed 1 month ago
This isn't a bug with Payload but rather with how Next.js caches pages in production. You need to add a hook to your collections that will instruct the Next.js cache to revalidate the relevant paths once it has been saved - see https://github.com/payloadcms/payload/blob/beta/templates/website/src/collections/Pages/hooks/revalidatePage.ts for an example.
Thanks!
I have resolved it with unstable_cache
like that:
import { getPayloadHMR } from "@payloadcms/next/utilities"
import config from '@payload-config'
import { unstable_cache } from "next/cache"
export default async function AnnouncementsList() {
const payload = await getPayloadHMR({ config })
const getCachedAnnouncements = unstable_cache(
async () => {
return await payload.find(
{
collection: 'announcements',
sort: '-start',
}
)
}, ['announcements'],
{
tags: ['announcements'],
revalidate: 60
}
)
const announcements = await getCachedAnnouncements()
return <div className="">
{
announcements.docs.map((a) => {
return <ul key={a.id} className="list-disc">
<li className="">{a.name}</li>
</ul>
})
}
</div>
}
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.
Link to reproduction
No response
Environment Info
Describe the Bug
The
list
is not updated on production after creating newAnnouncement
in/admin
(on dev it is OK):