Subscribe on changes!

Ref returned from composition outside of script setup no longer works after version 3.2.8

avatar
Sep 9th 2021

Version

3.2.11

Reproduction link

sfc.vuejs.org/

Steps to reproduce

  1. In SFC Playground, open the console;
  2. Click on "Hello" div.

What is expected?

It should appear in the console "clicked" and then "has value".

What is actually happening?

Only "clicked" appears .


In dev this works normally, but in build the container.value in useSomething remains null. Before version 3.2.8 it worked in both dev and build. I believe it may be related to https://github.com/vuejs/vue-next/pull/4492

avatar
Sep 9th 2021

As a workaround, wrap the container ref, it will be the same ref but the compiler will generate the appropriate code:

<script setup>
  import {ref } from 'vue'
  import { useSomething } from "./composition.js"  
  
  const { container, handleClick } = useSomething()
  const el = ref(container)
</script>

<template>
  <div ref="el" @click="handleClick">
    Hello
  </div>
</template>

Demo