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

[@vue/compiler-sfc] "xxx" is a destructured prop and should not be passed directly to watch() #8017

Closed
sqal opened this issue Apr 3, 2023 · 2 comments

Comments

@sqal
Copy link
Contributor

sqal commented Apr 3, 2023

Vue version

3.3.0-alpha.6
3.3.0-alpha.7

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9kEtPwzAQhP/KyhdaKQ+kShxCW5UjF4R69sVNNiQQP1jb7aHKf8d2GxSVikMem/mcmZ0zezGmOHpkFVvbmnrjwKLzZssVQC+NJgdnsJ0YBn3aY5vBSbi6gxFa0hIewtEHriJca2Uj6y3SaxOADTTY9grfSRu7mIQK3rw8IMG4jKfCxV3rVe16rSKyx2+P1i2WcI46AIU4pKYJoBFOVLNEi2U2SUik6a42xke6zaMmPiWdGz9f9kl7LhKSQYiz2cYM6T8RWZeXukJRYXAozSAcbtfl7ytXLGOXCnMpTPFptQo1p0X4VbCcVdNqnIUy48xZ55yxVVl6Zb4+ilrLche0krxyvcS80XK3KlbFYy4G04niqWx66+ZygVbmB9Kn0Hkw5uzaQ/Iow8cjUk6oGiSkfz1v2Hu+N8gf72v3Ixt/AMad00k=

Steps to reproduce

Open reproduction url and select vue version 3.3.0-alpha.6 or alpha.7 (for some reason SFC Playground doesn't remember the selected version)

What is expected?

Should compile vue component without error since all code is valid.

What is actually happening?

Compiler throws an error:

Error: [@vue/compiler-sfc] "error" is a destructured prop and cannot be directly watched. Use a getter () => error instead.

App.vue
13 |    const { error } = useRequest();
14 |  
15 |    watch(error, () => {
   |          ^^^^^
16 |  
17 |    });

But if you remove const { userId } = defineProps({ userId: Number }) then the error is gone.

@FliPPeDround
Copy link

According to the @vue/compiler-sfc error message, you can use it like this

const { error } = useRequest();
watch(() => error, () => {
});

@baiwusanyu-c
Copy link
Member

baiwusanyu-c commented Apr 4, 2023

I think maybe this is a bug. When the compiler checks watch and toRef, it also checks variables that are not props destructured, but these variables should not be checked. And the behavior it exhibits is inconsistent with previous versions, which is enough to show that it is a bug
wdyt? @sxzz 👀

IAmSSH pushed a commit to IAmSSH/core that referenced this issue May 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants