@@ -123,10 +123,18 @@ const proxyHandler: ProxyHandler<ProxyDraft> = {
123123 return value ;
124124 }
125125 // Ensure that the assigned values are not drafted
126- if ( value === peek ( target . original , key ) && ! arrayHandling ) {
126+ if (
127+ ! arrayHandling &&
128+ ( value === peek ( target . original , key ) ||
129+ target . options . skipFinalization ! . has ( value ) )
130+ ) {
131+ const has = target . options . skipFinalization ! . has ( value ) ;
132+ if ( target . options . skipFinalization ! . has ( value ) ) {
133+ target . options . skipFinalization ! . delete ( value ) ;
134+ }
127135 ensureShallowCopy ( target ) ;
128136 target . copy ! [ key ] = createDraft ( {
129- original : target . original [ key ] ,
137+ original : has ? target . copy ! [ key ] : target . original [ key ] ,
130138 parentDraft : target ,
131139 key : target . type === DraftType . Array ? Number ( key ) : key ,
132140 finalities : target . finalities ,
@@ -142,9 +150,10 @@ const proxyHandler: ProxyHandler<ProxyDraft> = {
142150 }
143151 return target . copy ! [ key ] ;
144152 }
145- if ( arrayHandling && ! isDraft ( value ) ) {
153+ if ( arrayHandling && ! isDraft ( value ) && isDraftable ( value ) ) {
146154 target . options . skipFinalization ! . add ( value ) ;
147- } else if ( target . options . skipFinalization ! . has ( value ) ) {
155+ }
156+ if ( ! arrayHandling && target . options . skipFinalization ! . has ( value ) ) {
148157 target . options . skipFinalization ! . delete ( value ) ;
149158 }
150159 return value ;
@@ -299,7 +308,11 @@ export function createDraft<T extends object>(createDraftOptions: {
299308 }
300309 finalizeSetValue ( proxyDraft ) ;
301310 finalizePatches ( proxyDraft , generatePatches , patches , inversePatches ) ;
302- if ( __DEV__ && target . options . enableAutoFreeze ) {
311+ if (
312+ __DEV__ &&
313+ target . options . enableAutoFreeze &&
314+ typeof updatedValue === 'object'
315+ ) {
303316 target . options . updatedValues =
304317 target . options . updatedValues ?? new WeakMap ( ) ;
305318 target . options . updatedValues . set ( updatedValue , proxyDraft . original ) ;
0 commit comments