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

Duplicated content #748

Closed
MartinKolarik opened this issue May 27, 2014 · 4 comments
Closed

Duplicated content #748

MartinKolarik opened this issue May 27, 2014 · 4 comments

Comments

@MartinKolarik
Copy link
Member

Seems like another crazy edge case. I discovered it more or less accidentally and if I use the build from 2014-05-08 it works correctly.

I wasn't able to reproduce it in the fiddle, but you can find the code here and the live version here. For some reason if this line is present, each project is inserted twice.

I noticed that it works with non-zero index (e.g. this.assets[1].files). @Rich-Harris can you take a look when you have some time?

@MartinKolarik
Copy link
Member Author

I was checking if the bug is still there with the current build and tried to isolate the problem once again and here we are: http://jsfiddle.net/px5R6/

Rich-Harris added a commit that referenced this issue Jun 30, 2014
Rich-Harris added a commit that referenced this issue Jun 30, 2014
fixes double rendering bug (#748)
@Rich-Harris
Copy link
Member

This was caused by the x.sort() inside the function - it triggered a fresh batch of updates (because array.sort() calls are intercepted, just like push, pop etc) which caused the outer section's setValue() method to be called twice. The second time round, it didn't realise it had already queued up some DOM to be rendered, hence the glitch.

The fix is to set an updating flag, and bug out if setValue() gets called from inside itself.

Ack, Travis reported an error while I was writing this comment... some node tests failed. BRB...

@Rich-Harris
Copy link
Member

Fixed the failing test. Was (yet another) PhantomJS bug - turns out it can't even sort arrays properly. Facepalm.

@CoryDanielson
Copy link

Instead of creating a copy of the array, you could do

Array.prototype.sort.call(arr, sortFn);

This seems to avoid the array.sort() call being intercepted while conserving memory.

Edit: Nevermind. This works the same as calling .slice() because Array.prototype.sort.call will also create a copy.

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

No branches or pull requests

3 participants