Skip to content

no-invalid-template-root fails on self-closing root #36

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

Closed
privatenumber opened this issue Jun 19, 2017 · 9 comments · Fixed by #116
Closed

no-invalid-template-root fails on self-closing root #36

privatenumber opened this issue Jun 19, 2017 · 9 comments · Fixed by #116

Comments

@privatenumber
Copy link
Contributor

privatenumber commented Jun 19, 2017

My root element is a self-closing textarea element and I get the error:
The template root requires an element rather than texts vue/no-invalid-template-root

@mysticatea
Copy link
Member

Thank you for this report.

Could you tell us detail information?

  • eslint verison
  • eslint-plugin-vue version
  • Your configuration
  • Repro code

I'm guessing your situation is https://jsfiddle.net/3pv889zu/

@yyx990803 Vue.js supports self-closing in this case?

@mysticatea
Copy link
Member

I got it: https://jsfiddle.net/du2ng274/1/

@michalsnik
Copy link
Member

Btw @hirokiosame self-closing textarea is not a valid HTML5 tag and you should use proper <textarea></textarea> instead anyway.

@michalsnik michalsnik added this to the Official release milestone Jun 26, 2017
@privatenumber
Copy link
Contributor Author

@michalsnik Ah, thanks for mentioning that. I had created a custom textarea component where the root of that component was simply a textarea (not self-closing). However, the usage of the custom-component was self-closing.

@michalsnik
Copy link
Member

What's the status of this @mysticatea? Is the lack of new parser blocking us from fixing this?

@mysticatea
Copy link
Member

@michalsnik Yes.

  1. The content of <textarea>s is RCDATA, so the parser ignores all tags except </textarea> end tag. And HTML ignores self-closing, so all after <textarea/> become just text.
  2. In conversion process from HTML AST to Vue.js template AST, it moves the content of elements which end with /> to the next sibling of the element.

For example:

// source code
<template>
    <textarea/>
</template>

// HTML AST
<template> element
┣ "\n    " text node
┗ <textarea> element
   ┗ "\n</template>" text node

// Vue.js template AST of this plugin
<template> element
┣ "\n    " text node
┣ <textarea> element
┗ "\n</template>" text node    // ← this text node causes `no-invalid-template-root` error!

I'm working on this with new parser.

@mysticatea
Copy link
Member

mysticatea commented Jul 6, 2017

This bug exists only on the following elements which have the self-closing sign:

  • <title/>
  • <textarea/>
  • <style/>
  • <xmp/>
  • <iframe/>
  • <noembed/>
  • <noframes/>
  • <script/>
  • <noscript/>

Practically, I think only <textarea/> and <iframe/>.

@michalsnik
Copy link
Member

Alright @mysticatea, that all makes sense, thanks for explanation 👍 And what's the current state of the parser you're working on? No rush, I'm just trying to estimate possible date for the official release of this plugin. This and the other bug #56 are our blockers and both will be solved with the new parser.

@mysticatea
Copy link
Member

I'm working on every weekends. I think I need 2 or 3 weeks.

@mysticatea mysticatea self-assigned this Jul 20, 2017
mysticatea added a commit that referenced this issue Aug 1, 2017
…116)

* Chore: upgrade dependencies
* Fix: several bugs and improve syntax errors (fixes #36, fixes #56, fixes #96)
* add more tests.
filipalacerda pushed a commit to filipalacerda/eslint-plugin-vue that referenced this issue Aug 5, 2017
* master:
  Add rule `vue/require-valid-default-prop`. (vuejs#119)
  3.10.0
  Update readme to 3.10.0
  Chore: remove package-lock.json (vuejs#128)
  Fix: parserService must exist always (fixes vuejs#125) (vuejs#127)
  Add rule `require-render-return`. (vuejs#114)
  3.9.0
  Update package-lock
  Update: options for `no-duplicate-attributes` (fixes vuejs#112)(vuejs#113)
  New: add rule `attribute-hyphenation`. (fixes vuejs#92)(vuejs#95)
  Add namespace check of svg & mathML instead of tag names (vuejs#120)
  ⚠️ Add support for deprecated state in update-rules ⚠️ (vuejs#121)
  Add rules: `no-dupe-keys` and `no-reserved-keys`. (vuejs#88)
  Chore: Improve tests for name-property-casing & improve documentation (vuejs#115)
  New: add `require-prop-types` rule (fixes vuejs#19)(vuejs#85)
  Update: upgrade vue-eslint-parser (fixes vuejs#36, fixes vuejs#56, fixes vuejs#96) (vuejs#116)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment