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

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

Closed
maxxcs opened this issue Sep 9, 2021 · 1 comment · Fixed by #4549
Closed
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working scope: compiler

Comments

@maxxcs
Copy link

maxxcs commented Sep 9, 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 #4492

@posva
Copy link
Member

posva commented Sep 9, 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working scope: compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants