From 63cef265c2b3b74b92ac5328c5bbc98183a471b2 Mon Sep 17 00:00:00 2001 From: Francisco Solla Date: Tue, 25 Aug 2026 12:23:40 -0300 Subject: [PATCH] =?UTF-8?q?react-audit(fam=C3=ADlia=205):=20Media.ts=20sem?= =?UTF-8?q?=20hooks=20de=20revalida=C3=A7=C3=A3o=20=E2=80=94=20getCachedDo?= =?UTF-8?q?cumentById('media')=20(documentReads.ts:43)=20nunca=20invalidav?= =?UTF-8?q?a=20em=20edi=C3=A7=C3=A3o/dele=C3=A7=C3=A3o=20no=20admin;=20aft?= =?UTF-8?q?erChange+afterDelete=20espelham=20Post/Petition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/collections/Media.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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',