-
-
Notifications
You must be signed in to change notification settings - Fork 681
Warn destructing attrs & slots #1964
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
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
vue/no-setup-slot-destructure
& vue/no-setup-attrs-destructure
We have a similar rule: https://eslint.vuejs.org/rules/no-setup-props-destructure.html Maybe it could be modified to also check attrs and slots. |
Related to #1949. |
Hmm... So they should be used more carefully. I find it difficult to check well. For example, use onBeforeUpdate to handle: setup(props, { attrs, slots }) {
let { slotFoo, slotBar } = slots
let { id, hidden } = attrs
// ...
onBeforeUpdate(() => {
;({ slotFoo, slotBar } = slots)
;({ id, hidden } = attrs)
// ...
})
} Using destructuring, but I don't think the above is wrong. |
They are stateful as mentioned in docs |
Yes. In other words, the example code you provided is neither right nor wrong. setup(props, { attrs, slots }) {
const { slotFoo, slotBar } = slots
const { id, hidden } = attrs
} What would your proposed rule check for? |
It will assure that we don't destructure the attrs & slots. In my lib anu-vue I previously had this destructuring which was causing reactivity lost. E.g. If I pass Thanks. |
Did you fix it? I think the |
Let me check |
Below code in my playground is working fine on main branch: <script lang="ts" setup>
import { ref } from "vue";
const inputType = ref("password");
const toggleType = () => {
console.log("clicked");
inputType.value = inputType.value === "text" ? "password" : "text";
};
</script>
<template>
<AInput :type="inputType" modelValue="text"></AInput>
<ABtn @click="toggleType">Toggle type</ABtn>
</template> Now even docs is confusing me 🤣 It states attrs & slots "stateful objects". Moreover, there's also "properties of attrs and slots are not reactive". IG someone better than me needs to comment on this or I should try this in SFC playground. |
Can you provide a SFC playground link to try out your components? |
Please describe what the rule should do:
What category should the rule belong to?
[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
Additional context
According to vue docs, destructured
attrs
&slots
aren't reactive. Hence, we should not destructure them insetup
function.EDIT: Sample code updated, Thanks @FloEdelmann
The text was updated successfully, but these errors were encountered: