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

HTML comment breaks automatic attribute inheritance #5203

Closed
vincerubinetti opened this issue Jan 3, 2022 · 2 comments · Fixed by #8593
Closed

HTML comment breaks automatic attribute inheritance #5203

vincerubinetti opened this issue Jan 3, 2022 · 2 comments · Fixed by #8593
Labels
🐞 bug Something isn't working 🔩 p2-edge-case

Comments

@vincerubinetti
Copy link

vincerubinetti commented Jan 3, 2022

Version

3.2.26

Reproduction link

sfc.vuejs.org/

Steps to reproduce

See the minimal reproduction. As is, the class="red" attribute is not passed down to the component. Try removing "comment B" from the component, and it will work. Or, if you move it underneath/within the v-else, it will also work.

What is expected?

HTML comments in the template should have no affect on the underlying styles, behavior, CSS, JS, Vue, or anything.

What is actually happening?

An HTML comment, combined with v-if, is confusing vue's ability to automatically inherit attributes.

@vincerubinetti
Copy link
Author

More info:

Error message

Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
 at <HelloWorld class="red">

App

<template>
  <HelloWorld class="red">Test</HelloWorld>
</template>

<script>
import HelloWorld from "./HelloWorld.vue";

export default {
  name: "App",
  components: {
    HelloWorld,
  },
};
</script>

<style>
.red {
  color: red;
}
</style>

Component

<template>
  <!-- comment A -->
  <span v-if="false">
    <slot />
  </span>

  <!-- comment B -->
  <div v-else>
    <slot />
  </div>
</template>

@sylann
Copy link

sylann commented Mar 22, 2022

Putting a comment immediately under <template> also breaks the behavior of <Transition>.

MyComponent.vue

<template>
  <!-- Root comment -->
  <div>some content</div>
</template>

Usage

<Transition name="fade">
  <MyComponent v-if="visible" />
</Transition>

The transition enters correctly, but there is no transition on leave.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working 🔩 p2-edge-case
Projects
None yet
3 participants