@@ -35,7 +35,7 @@ export function isEqual(document1: DatabasePageItem, document2: DatabasePageItem
3535 }
3636 }
3737
38- if ( JSON . stringify ( documentData1 ) !== JSON . stringify ( documentData2 ) ) {
38+ if ( ! isDeepEqual ( refineDocumentData ( documentData1 ) , refineDocumentData ( documentData2 ) ) ) {
3939 return false
4040 }
4141
@@ -49,3 +49,34 @@ export function isEqual(document1: DatabasePageItem, document2: DatabasePageItem
4949
5050 return true
5151}
52+
53+ function refineDocumentData ( doc : Record < string , unknown > ) {
54+ if ( doc . seo ) {
55+ const seo = doc . seo as Record < string , unknown >
56+ doc . seo = {
57+ ...seo ,
58+ title : seo . title || doc . title ,
59+ description : seo . description || doc . description ,
60+ }
61+ }
62+ // documents with same id are being compared, so it is safe to remove `path` and `__hash__`
63+ Reflect . deleteProperty ( doc , '__hash__' )
64+ Reflect . deleteProperty ( doc , 'path' )
65+ return doc
66+ }
67+
68+ function isDeepEqual ( obj1 : Record < string , unknown > , obj2 : Record < string , unknown > ) {
69+ if ( typeof obj1 !== 'object' || typeof obj2 !== 'object' ) return obj1 === obj2
70+
71+ const keys1 = Object . keys ( obj1 ) . filter ( k => obj1 [ k ] != null )
72+ const keys2 = Object . keys ( obj2 ) . filter ( k => obj2 [ k ] != null )
73+
74+ if ( keys1 . length !== keys2 . length ) return false
75+
76+ for ( const key of keys1 ) {
77+ if ( ! keys2 . includes ( key ) ) continue // Ignore missing null/undefined fields
78+ if ( ! isDeepEqual ( obj1 [ key ] as Record < string , unknown > , obj2 [ key ] as Record < string , unknown > ) ) return false
79+ }
80+
81+ return true
82+ }
0 commit comments