Subscribe on changes!

inconsistency between reactive and shallowReactive

avatar
Oct 13th 2020

Version

3.0.0

Reproduction link

https://codepen.io/SeregPie/pen/MWeamRG

Steps to reproduce

let object = {a: {b: 1}};
console.log(isReactive(shallowReactive(object).a)); // false
console.log(isReactive(reactive(object).a)); // false

but

let object = {a: {b: 1}};
console.log(isReactive(reactive(object).a)); // true
console.log(isReactive(shallowReactive(object).a)); // true

let object = {a: ref(1)};
console.log(isRef(reactive(object).a)); // false
console.log(isRef(shallowReactive(object).a)); // false

but

let object = {a: ref(1)}; 
console.log(isRef(shallowReactive(object).a)); // true
console.log(isRef(reactive(object).a)); // true

What is expected?

The order of the function calls should not matter, because those functions do not alter the original object.

What is actually happening?

Some unexpected things.

avatar
Oct 13th 2020

Maybe some clear definitions are needed.

Here are my proposals.

// nested object
let object = {a: {b: 1}};
console.log(isReactive(shallowReactive(object).a)); // should always be false
console.log(isReactive(reactive(object).a)); // should always be true
// ref in object
let object = {a: ref(1)}; 
console.log(isRef(shallowReactive(object).a)); // should always be false
console.log(isRef(reactive(object).a)); // should always be false
// nested ref in object
let object = {a: {b: ref(1)}}; 
console.log(isRef(shallowReactive(object).a.b)); // should always be true
console.log(isRef(reactive(object).a.b)); // should always be false
// special cases
let object = {a: {b: 1}};
console.log(shallowReactive(reactive(object)) === reactive(object)); // should always be true
console.log(reactive(shallowReactive(object)) === shallowReactive(object)); // ???
avatar
Oct 13th 2020

you cannot pass the same object to two different reactive, ref, etc functions. It has to be a different object every time:

console.log(isReactive(shallowReactive({a:{b:1}}).a)); // should always be false
console.log(isReactive(reactive({a:{b:1}}).a)); // should always be true