@@ -3,7 +3,6 @@ import { Directions } from '@lib/selects'
33import { Project } from '@/payload-types'
44import { colorField } from '@/lib/utils/colors'
55import { revalidatePath } from 'next/cache'
6- import { AssertionError , deepStrictEqual } from 'assert' // Validation always runs on the server so it's safe to use this
76import { routing } from '@/i18n/routing'
87import draftAccess from '@/lib/utils/access'
98import 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