Subscribe on changes!

`in` operator not working correctly with component instance `exposeProxy`

avatar
Jun 18th 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?

https://github.com/vuejs/core/blob/25f7a16a6eccbfa8d857977dcf1f23fb36b830b5/packages/runtime-core/src/component.ts#L934-L949

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).