Skip to content
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

in operator not working correctly with component instance exposeProxy #6137

Closed
DrJume opened this issue Jun 18, 2022 · 0 comments · Fixed by #6138
Closed

in operator not working correctly with component instance exposeProxy #6137

DrJume opened this issue Jun 18, 2022 · 0 comments · Fixed by #6138
Labels
🐞 bug Something isn't working

Comments

@DrJume
Copy link
Contributor

DrJume commented Jun 18, 2022

Vue version

3.2.37

Link to minimal reproduction

https://stackblitz.com/edit/vuejs-issue-repro-in-operator-expose-proxy?file=src%2FApp.vue

Steps to reproduce

  1. Create a component which uses expose({...}) in the setup() function.
  2. Use this component in another Vue component and use a template ref to access its instance.
  3. Access templateRef.value in the mounted hook.

What is expected?

templateRef.value.$el // should evaluate to the HTML node correctly
'$el' in templateRef.value // should be true

What is actually happening?

templateRef.value.$el // evaluates to the HTML node correctly ✅
'$el' in templateRef.value // is false ❌

System Info

No response

Any additional comments?

export function getExposeProxy(instance: ComponentInternalInstance) {
if (instance.exposed) {
return (
instance.exposeProxy ||
(instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
get(target, key: string) {
if (key in target) {
return target[key]
} else if (key in publicPropertiesMap) {
return publicPropertiesMap[key](instance)
}
}
}))
)
}
}

I suspect that the exposeProxy which uses the get() handler needs to implement the same logic in the Proxy's has() handler to fallback to checking if the checked property is defined in publicPropertiesMap[key](instance).

DrJume added a commit to DrJume/vuejs-core that referenced this issue Jun 18, 2022
…nce properties in `exposeProxy`

`exposeProxy` implements a fallback logic for accessing built-in instance properties but was missing the same logic for the `in` operator in the Proxy's `has()` handler.

fix vuejs#6137
@LinusBorg LinusBorg added the 🐞 bug Something isn't working label Jul 4, 2022
yyx990803 pushed a commit that referenced this issue Oct 26, 2022
chrislone pushed a commit to chrislone/core that referenced this issue Feb 4, 2023
zhangzhonghe pushed a commit to zhangzhonghe/core that referenced this issue Apr 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
2 participants