@@ -54,16 +54,14 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
5454 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
5555 thisArg ?: unknown ,
5656 ) {
57- const result = apply ( this , 'filter' , fn , thisArg )
58- return isProxy ( this ) && ! isShallow ( this ) ? result . map ( toReactive ) : result
57+ return apply ( this , 'filter' , fn , thisArg , v => v . map ( toReactive ) )
5958 } ,
6059
6160 find (
6261 fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
6362 thisArg ?: unknown ,
6463 ) {
65- const result = apply ( this , 'find' , fn , thisArg )
66- return isProxy ( this ) && ! isShallow ( this ) ? toReactive ( result ) : result
64+ return apply ( this , 'find' , fn , thisArg , toReactive )
6765 } ,
6866
6967 findIndex (
@@ -77,8 +75,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
7775 fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
7876 thisArg ?: unknown ,
7977 ) {
80- const result = apply ( this , 'findLast' , fn , thisArg )
81- return isProxy ( this ) && ! isShallow ( this ) ? toReactive ( result ) : result
78+ return apply ( this , 'findLast' , fn , thisArg , toReactive )
8279 } ,
8380
8481 findLastIndex (
@@ -237,11 +234,14 @@ function apply(
237234 method : ArrayMethods ,
238235 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
239236 thisArg ?: unknown ,
237+ wrappedRetFn ?: ( result : any ) => unknown ,
240238) {
241239 const arr = shallowReadArray ( self )
240+ let needsWrap = false
242241 let wrappedFn = fn
243242 if ( arr !== self ) {
244- if ( ! isShallow ( self ) ) {
243+ needsWrap = ! isShallow ( self )
244+ if ( needsWrap ) {
245245 wrappedFn = function ( this : unknown , item , index ) {
246246 return fn . call ( this , toReactive ( item ) , index , self )
247247 }
@@ -252,7 +252,8 @@ function apply(
252252 }
253253 }
254254 // @ts -expect-error our code is limited to es2016 but user code is not
255- return arr [ method ] ( wrappedFn , thisArg )
255+ const result = arr [ method ] ( wrappedFn , thisArg )
256+ return needsWrap && wrappedRetFn ? wrappedRetFn ( result ) : result
256257}
257258
258259// instrument reduce and reduceRight to take ARRAY_ITERATE dependency
0 commit comments