Subscribe on changes!

proxy not contain a compoennt value on the prod env(dev is ok)

avatar
Nov 11th 2022

Vue version

3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#__DEV__eNq1U0tu1EAQvUrhjT1i7FYmC6SRPQRlAwt2SGx6Y+yascH9UXd7CLJ8Ec7CnbgC1W7HmcwgIiJl5/r0e1WvnofondbZscdoG+W2Mq12YNH1esdlK7QyDgYwuF/DAd1tbwxK90FaV8oKYYS9UQJieh4v7VXTdvXVXMlYCD0DtVSKnoKwByg8aBK/x65T8FmZrn4Vr7jMWZiB2ClwKHRXOqQIIG+udsMwPR7HnFE0ZVupewfHVKgau4JHVOdRKAXqXT7PQMmcLZDROgoDp6LU2VerJCkw+Hd8LlgebWHK+Bwt4GMeNc5pu2Wsl/rbIauUYDdUY6aXrhWY1krcXGeb7PoNq1vrTvMZWpF+Meq7RUOMPFqfgDNKHtGkJHCNBs0/yc56HxGe1S5IPefI5UgCPNzmyesr+VHRJlj//egD9BZvPdxSp9MrIZQk0jNzbB6bYzObg4SYDTLAvpcEVCyoCXnjwjyfmtZCa3//+umtw+UyY5KsoNh5kCQOO8arqeP/7RUmZBfeWXYj5RYNnvxFuMS7qZdGq1yr5MmCwWr3Amij7n5MElyCejHgAcKvKUuBM0LAUB1mnTokcVPaaam38Rpi+oihlQF9QoHwnfmW1wV4nNkgQCK73sh7VKI5t850uRe3zgv6YvM8X5xaYfwDNIbPsg==

Steps to reproduce

common.js :

import { getCurrentInstance } from 'vue'

export function useChild() {
  const { proxy } = getCurrentInstance()
  function fun(name) {
    console.log('has msg ?', 'msg' in proxy)
    proxy.msg += name
  }
  return {
    fun
  }
}

app.vue :

<script setup>
import { ref, getCurrentInstance } from 'vue'
import child1 from './child1.vue'
const msg = ref('Hello World!')
</script>

<template>
  <h1>{{ msg }}</h1>
  <input v-model="msg">
  <child1></child1>
</template>

child1.vue :

<script setup>
import { ref, onMounted } from 'vue'
import { useChild } from './common.js'
import child2 from './child2.vue'
  
const { fun } = useChild()
const msg = ref('This is:')

onMounted(() => fun('child1'))

</script>

<template>
  <h1>{{ msg }}</h1>
  <child2/>
</template>

What is expected?

in prod env, The proxy contain msg

What is actually happening?

in prod env, The proxy not contain msg

System Info

No response

Any additional comments?

No response

avatar
Nov 11th 2022

add:

//work in this case
<script lang="ts">
   setup() {
     // do something.....
   }
</script>
// not work
<script lang="ts" setup>
</script>
avatar
Nov 11th 2022

This has been fixed in 3.2.45, but maybe not in the way you want it to. See:

https://github.com/vuejs/core/issues/6248 https://github.com/vuejs/core/commit/f73925d76a76ee259749b8b48cb68895f539a00f