Skip to content

Commit afbf196

Browse files
committed
Force revalidate projects page on project update
1 parent 8ccdbc6 commit afbf196

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/collections/Projects.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Directions } from '@lib/selects'
33
import { Project } from '@/payload-types'
44
import { colorField } from '@/lib/utils/colors'
55
import { revalidatePath } from 'next/cache'
6-
import { AssertionError, deepStrictEqual } from 'assert' // Validation always runs on the server so it's safe to use this
76
import { routing } from '@/i18n/routing'
87
import draftAccess from '@/lib/utils/access'
98
import purgeURL from '@/lib/utils/purge'
@@ -273,7 +272,7 @@ export const Projects: CollectionConfig = {
273272
},
274273
hooks: {
275274
afterChange: [
276-
async ({ doc, req, previousDoc }) => {
275+
async ({ doc, req }) => {
277276
// Ignore draft updates
278277
// Only revalidate cache when a document has been published
279278
if (doc._status === 'published') {
@@ -285,27 +284,18 @@ export const Projects: CollectionConfig = {
285284
routing.locales.forEach(async (locale) => {
286285
revalidatePath(`/${locale}${updateURL}`)
287286
await purgeURL(`${locale}${updateURL}`) // Purge nginx cache
287+
288+
// Revalidate projects page in case name or thumbnail were changed
289+
revalidatePath(`/${locale}/projects`)
290+
await purgeURL(`${locale}/projects`)
288291
})
289292
else {
290293
revalidatePath(`/${updatedLocale}${updateURL}`)
291294
await purgeURL(`${updatedLocale}${updateURL}`)
292-
}
293295

294-
// If either the thumbnail or project name was changed revalidate the projects page
295-
// Using try...catch since deeepStrictEqual raises an AssertionError if the values don't match
296-
try {
297-
if (doc.name !== previousDoc.name) throw new AssertionError()
298-
deepStrictEqual(doc.thumbnail, previousDoc.thumbnail)
299-
} catch {
300-
if (updatedLocale === 'all')
301-
routing.locales.forEach(async (locale) => {
302-
revalidatePath(`/${locale}/projects`)
303-
await purgeURL(`${locale}/projects`)
304-
})
305-
else {
306-
revalidatePath(`/${updatedLocale}/projects`)
307-
await purgeURL(`${updatedLocale}/projects`)
308-
}
296+
// Revalidate projects page in case name or thumbnail were changed
297+
revalidatePath(`/${updatedLocale}/projects`)
298+
await purgeURL(`${updatedLocale}/projects`)
309299
}
310300
}
311301
},

0 commit comments

Comments
 (0)