Description
Version
2.5.13
Reproduction link
https://jsfiddle.net/aoxo2rod/8/
Steps to reproduce
Run the JSFiddle
What is expected?
The background should be green, styled by ul:empty
, as the children of ul
are all conditionally not rendered: empty v-for
and v-if
that evaluate to false.
What is actually happening?
The background is red, ul:empty
is not used because there is a blank space inside the ul
tags, which CSS doesn't consider to be :empty
.
The multiple children elements are important, a single li
element with v-if="false"
will produce the correct result. It appears Vue is putting a blank space between the elements, even if they are conditionally not rendered (appearing as <!---->
instead). It's worth noting that if you manually remove the extra spaces using developer tools, everything looks as expected, <!---->
does not affect :empty
.
Furthermore, this only reproduces if there is a newline between the elements. Modifying the provided JSFiddle to only have the two li
with v-if="false"
will produce the correct result if there's no newline between them. So Vue seems to be turning the newline between the elements into a single space, which is causing the issue.