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/no-v-text-v-html-on-component: it should not warn if a component implements default slot #2431
Comments
The behaviour of this rule is correct in my opinion, because v-html does not use the default slot. Instead you could achieve the behaviour without security risks like this: <template>
<div class="wrap"><slot /></div>
</template>
<MyComponent>
{{ foobar }}
</MyComponent> or you can pass a foobar component instead. <template>
<div class="wrap"><slot /></div>
</template>
<MyComponent>
<Foobar />
</MyComponent> |
That is different from what I am observing in recent versions of Vue.
That is covered by
Then whole content is replaced, including
my testing indicated that See example here: App.vue: <script setup>
import { ref } from 'vue'
import Comp from './Comp.vue'
const html = `<div class="inner">Inner</div>`
</script>
<template>
<div class="component"><Comp v-html="html" /></div>
</template> Comp.vue: <script setup></script>
<template>
<div class="wrap">
<slot />
</div>
</template> This renders for me: <div class="component"><div class="wrap"><div class="inner">Inner</div></div></div> Which is what I would expect. |
Regardless, it is hard for eslint-plugin-vue to determine whether a component has slots at all, since we don't have access to other files. You can manually ignore those components using the |
I see. Still, it might be useful to document when it is safe to use |
Sure, documentation improvement PRs are always welcome!
Hmm, without a default slot. But it is useful to always avoid the "
Can you elaborate what you would split out to a separate rule? Note that other rules also can't know which components have (default) slots without reading multiple files. |
I understand that it is not possible to write such a rule without reading multiple files. But, it seems to me there are three issues here:
I think the issue is really only 3., providing content to a component without slot is problematic, or it is ignored or it overrides existing content. So rule should warn.
Currently So I think |
For reference, this is the original issue: #1724 |
Try this
|
Nice. This really does not work. Thanks. I have found only this issue about this behavior is Vue core, but it looks it is just about SSR? |
What rule do you want to change?
vue/no-v-text-v-html-on-component
Does this change cause the rule to produce more or fewer warnings?
Fewer warnings (less false positives).
How will the change be implemented? (New option, new default behavior, etc.)?
New default behavior.
Please provide some example code that this change will affect:
What does the rule currently do for this code?
It complains with
vue/no-v-text-v-html-on-component
.What will the rule do after it's changed?
It does not complain. Because there is default slot defined, v-html is correctly used for the slot content and does not remove the wrap div.
The text was updated successfully, but these errors were encountered: