Skip to content

Conversation

@chrisvfritz
Copy link
Contributor

Since 2 root nodes with v-if and v-else are guaranteed to return one vnode, they should be considered safe in the root of a template.

@LinusBorg
Copy link
Member

LinusBorg commented Jul 27, 2016

You also have to check for the absence of v-for on the element that has v-if, as the combination of both would potentially also result in more than one root element.

Or is that done somewhere else generally?

@chrisvfritz
Copy link
Contributor Author

@LinusBorg There's a separate warning for v-for on root, which is triggered whether or not a v-if exists.

@LinusBorg
Copy link
Member

I saw that but was unsure weither it only applies if there is one root item.

@chrisvfritz
Copy link
Contributor Author

@LinusBorg Just confirmed with another test locally that this:

<div v-if="1" v-for="i in [1]"></div><div v-else></div>

does indeed warn about v-for, but root constraints were not being applied to the 2nd element with v-else. Added a test for it and fixed the issue. 👍

@chrisvfritz
Copy link
Contributor Author

It perhaps should be noted that the following will currently NOT trigger a warning:

<p v-if="0"></p>
<p v-else></p>
<p v-else></p>

But I consider this a separate issue, since this doesn't warn in any context, even though it should probably be considered invalid. Also, the above code does still guarantee the return of a single vnode (either the first or last element - the 2nd element is seemingly ignored by the parser).

@yyx990803 yyx990803 merged commit 3e06c57 into vuejs:next Jul 29, 2016
@yyx990803
Copy link
Member

Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants