diff --git a/src/collections/Media.ts b/src/collections/Media.ts index 418226e2..2406d73b 100644 --- a/src/collections/Media.ts +++ b/src/collections/Media.ts @@ -1,4 +1,5 @@ import { canManagePublishedContent } from '@/utilities/campaignAccess' +import { revalidateDocumentById } from '@/utilities/documents' import type { CollectionConfig } from 'payload' export const Media: CollectionConfig = { @@ -18,6 +19,21 @@ export const Media: CollectionConfig = { update: canManagePublishedContent, delete: canManagePublishedContent, }, + // The public pages read media through `getCachedDocumentById('media', …)` + // (`unstable_cache` under the `document_media:` tag), so admin edits and + // deletions must bust that cache — same contract as Post/Petition. + hooks: { + afterChange: [ + ({ doc, previousDoc }) => { + revalidateDocumentById('media', previousDoc?.id ?? doc.id) + }, + ], + afterDelete: [ + ({ doc }) => { + revalidateDocumentById('media', doc.id) + }, + ], + }, fields: [ { name: 'alt',