@@ -36,7 +36,8 @@ const arrayInstrumentations: Record<string, Function> = {}
3636
3737function createGetter ( isReadonly = false , shallow = false ) {
3838 return function get ( target : object , key : string | symbol , receiver : object ) {
39- if ( isArray ( target ) && hasOwn ( arrayInstrumentations , key ) ) {
39+ const targetIsArray = isArray ( target )
40+ if ( targetIsArray && hasOwn ( arrayInstrumentations , key ) ) {
4041 return Reflect . get ( arrayInstrumentations , key , receiver )
4142 }
4243 const res = Reflect . get ( target , key , receiver )
@@ -48,18 +49,24 @@ function createGetter(isReadonly = false, shallow = false) {
4849 // TODO strict mode that returns a shallow-readonly version of the value
4950 return res
5051 }
51- // ref unwrapping, only for Objects, not for Arrays.
52- if ( isRef ( res ) && ! isArray ( target ) ) {
53- return res . value
52+ if ( isRef ( res ) ) {
53+ if ( targetIsArray ) {
54+ track ( target , TrackOpTypes . GET , key )
55+ return res
56+ } else {
57+ // ref unwrapping, only for Objects, not for Arrays.
58+ return res . value
59+ }
60+ } else {
61+ track ( target , TrackOpTypes . GET , key )
62+ return isObject ( res )
63+ ? isReadonly
64+ ? // need to lazy access readonly and reactive here to avoid
65+ // circular dependency
66+ readonly ( res )
67+ : reactive ( res )
68+ : res
5469 }
55- track ( target , TrackOpTypes . GET , key )
56- return isObject ( res )
57- ? isReadonly
58- ? // need to lazy access readonly and reactive here to avoid
59- // circular dependency
60- readonly ( res )
61- : reactive ( res )
62- : res
6370 }
6471}
6572
0 commit comments