Skip to content

Fixed v-for/v-if priority and explanations #540

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

Merged
merged 12 commits into from
Sep 25, 2020
Merged

Conversation

NataliaTepluhina
Copy link
Member

Description of Problem

In v3, the precedence of v-for and v-if when used on the same node is is now switched.

  • v2: v-for takes precedence over v-if
  • v3: v-if takes precedence over v-for

Proposed Solution

Update respective sections of the guide

Additional Information

Close #534

Copy link
Member

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!👍
Thanks quick fixes!

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NataliaTepluhina Thanks for inviting me to participate in the review for this.

I have made some suggestions, I hope they're helpful.


```html
<li v-for="todo in todos" v-if="!todo.isComplete">
<!-- Property "todo" was accessed during render but is not defined on instance. -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs moving up a line. It's potentially confusing because the next line also mentions todo. Perhaps that line should be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should remove this line altogether because we need to show that this code snippet is incorrect. I changed a message to reflect this better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I wasn't clear.

I wasn't suggesting removing the comment line. I was suggesting removing the next line, {{ todo }}. The problem is that it mentions todo, so it wasn't entirely clear whether the error message was referring to the v-if or the {{ todo }}.

Moving the comment up has helped. I just wonder whether replacing the {{ todo }} with, e.g. ... or a comment would remove any potential for someone to misunderstand? One of the earlier examples uses <!-- content -->, so perhaps that?

<li v-for="todo in todos" v-if="!todo.isComplete">
  <!-- content -->
</li>

Now I look a bit closer there's actually another problem with the {{ todo }}. The v-if="todo.isComplete" implies that todo is an object with an isComplete property but the {{ todo }} seems to be treating todo like it's a string. It isn't technically wrong, I just worry about someone getting distracted by the {{ todo }} and thinking it has something to do with the error.

If you do decide to change it then the next example would need updating to match.

@NataliaTepluhina
Copy link
Member Author

@skirtles-code thank you for the awesomely thorough review and suggestions! I've applied fixes, would you mind taking a second look?

Copy link
Member

@phanan phanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 I'm being an annoying nitpicker again and left some non-blocking comments.

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NataliaTepluhina I've made one more comment trying to clarify my earlier suggestion about one of the examples. I might just be worrying about nothing.

Happy for this to be merged if you don't think it's worth changing.

Copy link
Member

@bencodezen bencodezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this @NataliaTepluhina! Other than the phrasing suggestions An added in the PR, it looks good to me!

NataliaTepluhina and others added 2 commits September 25, 2020 17:58
Co-authored-by: Phan An <me@phanan.net>
Co-authored-by: Phan An <me@phanan.net>
@NataliaTepluhina NataliaTepluhina merged commit 7cb38f9 into master Sep 25, 2020
nick-lai pushed a commit to nick-lai/docs-next that referenced this pull request Dec 2, 2020
* fix: fixed v-if v-for on styleguide

* fix: fixed directives API for v-if v-for

* fix: fixed v-if with v-for on list

* fix: fixed conditional for v-if

* fix: fixed typo

* fix: fixed directives.md

* fix:  fixed error on list

* fix: fixed grammar

* fix: fixed styleguide `li` mention

* fix: fixed grammar

* Update src/api/directives.md

Co-authored-by: Phan An <me@phanan.net>

* Update src/guide/conditional.md

Co-authored-by: Phan An <me@phanan.net>

Co-authored-by: Phan An <me@phanan.net>
@NataliaTepluhina NataliaTepluhina deleted the v-for-v-if-fix branch February 24, 2021 08:34
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.

List Rendering should switch to say that v-if has a higher priority over v-for
5 participants