-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using reactive and shallowReactive on the same target returns the same proxy for both calls. #2843
Comments
IMO, this will make |
I do not think so, because i think 'shallow' can show the difference, i think we should use 4 weakMap (reactiveMap, shallowReactiveMap, readolyMap, shallowReadonlyMap) to store the map relationship of the origin object to the proxy instead of the 2 maps(reactiveMap and readonlyMap) |
I think that changing the order of creation of |
We collect all reactive instances in one WeakMap, that ignores what type of This likely affects |
the actions of reactive and shallowReactive are different? why we ignore the difference? |
i have the origin object, first i reactive origin and get reactive, second i shallowReactive the origin, but i get the reactive, can not get the shallowReactive, and i do not know the result is the reactive, this is confused,because of this, cause the bug #2846 |
yes. This is why we marked it as a bug. I will close your othr issues as a duplicate |
PR submitted, happy to get reviews. |
Insert code like this in markdown. |
@LinusBorg in you code of pr, i found some improve, i think should modify below export function reactive(target: object) {
return createReactiveObject(
target,
false,
mutableHandlers,
mutableCollectionHandlers,
reactiveMap
)
}
function createReactiveObject(
target: Target,
isReadonly: boolean,
baseHandlers: ProxyHandler<any>,
collectionHandlers: ProxyHandler<any>,
proxyMap: WeakMap<Target, any>
) {
if (!isObject(target)) {
if (__DEV__) {
console.warn(`value cannot be made reactive: ${String(target)}`)
}
return target
}
// target already has corresponding Proxy
let existingProxy = proxyMap.get(target)
if (existingProxy) {
return existingProxy
}
// target is already a Proxy, should toRaw prevent new proxy again
// exception: calling readonly() on a reactive object
if (
target[ReactiveFlags.RAW] &&
!(isReadonly && target[ReactiveFlags.IS_REACTIVE])
) {
target = toRaw(target)
existingProxy = proxyMap.get(target)
if(existingProxy ) {
return existingProxy
}
}
// only a whitelist of value types can be observed.
const targetType = getTargetType(target)
if (targetType === TargetType.INVALID) {
return target
}
const proxy = new Proxy(
target,
targetType === TargetType.COLLECTION ? collectionHandlers : baseHandlers
)
proxyMap.set(target, proxy)
return proxy
} |
Version
3.0.4
Reproduction link
https://jsfiddle.net/vqkho2xt/2/
Steps to reproduce
const origin = {};
const shallowProxy = shallowReactive(origin);
const reactiveProxy = reactive(origin);
console.log(shallowProxy === reactiveProxy);
What is expected?
shallowProxy !== reactiveProxy
What is actually happening?
shallowProxy === reactiveProxy
why reactive and shallowReactive should return diffrent object ?
may there is the situation: we maybe want to get two different Proxy with the same origin object, the proxy named reactiveProxy returned by reactive , the proxy named shallowProxy returned by shallowReactive, we change the origin object
s deep property by reactiveProxy can trigger denpendencies of the deep propery, but we change the origin object
s deep property by shallowProxy should not trigger denpendencies of the deep propery, in this situation, the implements of the vue3 can not satisfy because of that shallowReactive and reactive return the same proxy with the same origin object.The text was updated successfully, but these errors were encountered: