@@ -42,7 +42,19 @@ function isGetter(obj, prop) {
4242
4343export const dependenciesMap = new WeakMap ( ) ;
4444
45- function accumulateDeepEqualDiffs ( a , b , diffsAccumulator , pathString = '' , { detailed} ) {
45+ function accumulateDeepEqualDiffs ( a , b , diffsAccumulator , pathString = '' , { detailed, opaqueOverride} ) {
46+ // Check if either value should be treated as opaque
47+ if ( opaqueOverride ) {
48+ const aIsOpaque = opaqueOverride ( a ) ;
49+ const bIsOpaque = opaqueOverride ( b ) ;
50+ if ( aIsOpaque || bIsOpaque ) {
51+ // If either is opaque, only compare by reference
52+ return a === b ?
53+ trackDiff ( a , b , diffsAccumulator , pathString , diffTypes . same ) :
54+ trackDiff ( a , b , diffsAccumulator , pathString , diffTypes . different ) ;
55+ }
56+ }
57+
4658 if ( a === b ) {
4759 if ( detailed ) {
4860 trackDiff ( a , b , diffsAccumulator , pathString , diffTypes . same ) ;
@@ -63,7 +75,7 @@ function accumulateDeepEqualDiffs(a, b, diffsAccumulator, pathString = '', {deta
6375 const arrayItemDiffs = [ ] ;
6476 let numberOfDeepEqualsItems = 0 ;
6577 for ( let i = arrayLength ; i -- ; i > 0 ) {
66- const diffEquals = accumulateDeepEqualDiffs ( a [ i ] , b [ i ] , arrayItemDiffs , `${ pathString } [${ i } ]` , { detailed} ) ;
78+ const diffEquals = accumulateDeepEqualDiffs ( a [ i ] , b [ i ] , arrayItemDiffs , `${ pathString } [${ i } ]` , { detailed, opaqueOverride } ) ;
6779 if ( diffEquals ) {
6880 numberOfDeepEqualsItems ++ ;
6981 }
@@ -116,7 +128,7 @@ function accumulateDeepEqualDiffs(a, b, diffsAccumulator, pathString = '', {deta
116128 }
117129
118130 const reactElementPropsAreDeepEqual =
119- accumulateDeepEqualDiffs ( a . props , b . props , [ ] , `${ pathString } .props` , { detailed} ) ;
131+ accumulateDeepEqualDiffs ( a . props , b . props , [ ] , `${ pathString } .props` , { detailed, opaqueOverride } ) ;
120132
121133 return reactElementPropsAreDeepEqual ?
122134 trackDiff ( a , b , diffsAccumulator , pathString , diffTypes . reactElement ) :
@@ -133,7 +145,7 @@ function accumulateDeepEqualDiffs(a, b, diffsAccumulator, pathString = '', {deta
133145
134146 if ( aDependenciesObj && bDependenciesObj ) {
135147 const dependenciesAreDeepEqual =
136- accumulateDeepEqualDiffs ( aDependenciesObj . deps , bDependenciesObj . deps , diffsAccumulator , `${ pathString } :parent-hook-${ aDependenciesObj . hookName } -deps` , { detailed} ) ;
148+ accumulateDeepEqualDiffs ( aDependenciesObj . deps , bDependenciesObj . deps , diffsAccumulator , `${ pathString } :parent-hook-${ aDependenciesObj . hookName } -deps` , { detailed, opaqueOverride } ) ;
137149
138150 return dependenciesAreDeepEqual ?
139151 trackDiff ( a , b , diffsAccumulator , pathString , diffTypes . function ) :
@@ -144,6 +156,7 @@ function accumulateDeepEqualDiffs(a, b, diffsAccumulator, pathString = '', {deta
144156 }
145157
146158 if ( typeof a === 'object' && typeof b === 'object' && Object . getPrototypeOf ( a ) === Object . getPrototypeOf ( b ) ) {
159+
147160 const aKeys = Object . getOwnPropertyNames ( a ) ;
148161 const bKeys = Object . getOwnPropertyNames ( b ) ;
149162
@@ -183,7 +196,7 @@ function accumulateDeepEqualDiffs(a, b, diffsAccumulator, pathString = '', {deta
183196 let numberOfDeepEqualsObjectValues = 0 ;
184197 for ( let i = keysLength ; i -- ; i > 0 ) {
185198 const key = relevantKeys [ i ] ;
186- const deepEquals = accumulateDeepEqualDiffs ( a [ key ] , b [ key ] , objectValuesDiffs , `${ pathString } .${ key } ` , { detailed} ) ;
199+ const deepEquals = accumulateDeepEqualDiffs ( a [ key ] , b [ key ] , objectValuesDiffs , `${ pathString } .${ key } ` , { detailed, opaqueOverride } ) ;
187200 if ( deepEquals ) {
188201 numberOfDeepEqualsObjectValues ++ ;
189202 }
@@ -203,10 +216,10 @@ function accumulateDeepEqualDiffs(a, b, diffsAccumulator, pathString = '', {deta
203216 return trackDiff ( a , b , diffsAccumulator , pathString , diffTypes . different ) ;
204217}
205218
206- export default function calculateDeepEqualDiffs ( a , b , initialPathString , { detailed = false } = { } ) {
219+ export default function calculateDeepEqualDiffs ( a , b , initialPathString , { detailed = false , opaqueOverride } = { } ) {
207220 try {
208221 const diffs = [ ] ;
209- accumulateDeepEqualDiffs ( a , b , diffs , initialPathString , { detailed} ) ;
222+ accumulateDeepEqualDiffs ( a , b , diffs , initialPathString , { detailed, opaqueOverride } ) ;
210223 return diffs ;
211224 } catch ( error ) {
212225 if ( ( error . message && error . message . match ( / s t a c k | r e c u r s i o n / i) ) || ( error . number === - 2146828260 ) ) {
0 commit comments