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

#if _collection.any? around #each causes duplicate first item #36

Closed
derikson opened this issue Sep 19, 2014 · 10 comments
Closed

#if _collection.any? around #each causes duplicate first item #36

derikson opened this issue Sep 19, 2014 · 10 comments

Comments

@derikson
Copy link
Contributor

{#if _collection.any?}{#each _collection as c}{c.name}{/}{/} will cause the first item to be output twice, once at the beginning and once at the end. The same thing happens with .empty?, but does not happen with .size == 0.

You can test this by editing app/main/views/blog/edit.html in the todos3 app and wrapping the {#each _posts as post}{/} block with a {#if _posts.any?}{/} conditional.

@ryanstout
Copy link
Member

Thanks for the heads up. I think I know why this might be happening. I'll try and get it fixed tomorrow.

@derikson
Copy link
Contributor Author

Forgot one major detail. The bug doesn't occur right away. You have to reload the page for it to trigger.

@derikson
Copy link
Contributor Author

Check https://github.com/derikson/todos3/tree/topic/issue-36 for a demonstration of this bug. That's branch topic/issue-36, not master.

Go to blogs, enter a blog, then reload the page using the reload button in your browser. You should see a duplicate of the blog entry.

@derikson
Copy link
Contributor Author

I noticed {#if _posts.size > 0} and {#if _posts.length > 0} don't trigger the bug, while {#if _posts.count > 0} does. ReactiveArray has an implementation for #count, but relies on method_missing for the other two. Maybe that's just a coincidence, though.

@derikson
Copy link
Contributor Author

Removing the #count method in ReactiveArray doesn't change anything, so it's just a coincidence.

@derikson
Copy link
Contributor Author

Stepping over the javascript, I found that the call to #reload in EachBinding#initialize creates the extra element when the bug is triggered.

@ryanstout
Copy link
Member

@derikson Thanks. I'm pretty sure the new reactive will fix this issue. Should be out early next week.

@ryanstout
Copy link
Member

@derikson Can you use volt 0.8 and see if you can duplicate this? (You might have to do a new app) I wasn't able to duplicate. Closing for now. Feel free to re-open.

@derikson
Copy link
Contributor Author

derikson commented Nov 3, 2014

It can't replicate the bug anymore. Confirmed fixed.

@ryanstout
Copy link
Member

Thanks

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

No branches or pull requests

2 participants