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

can.batch.start/stop causes can.List with length>1 to render last element twice #680

Closed
stevenvachon opened this issue Jan 19, 2014 · 4 comments · Fixed by #1458
Closed
Labels
Milestone

Comments

@stevenvachon
Copy link
Contributor

{{#each arr}} {{.}} {{/each}}
for (var i=1; i<=2; i++) {
    this.arr.push(i);
}

will produce 1,2, however:

can.batch.start();
for (var i=1; i<=2; i++) {
    this.arr.push(i);
}
can.batch.stop();

will produce 1,2,2.

?

http://jsfiddle.net/prometh/34YZP/

@stevenvachon
Copy link
Contributor Author

Updated fiddle with can.stache. The issue persists.

@gsmeets
Copy link
Contributor

gsmeets commented Oct 9, 2014

ah, this might explain why I am having my last item rendered twice in a select list.

@stevenvachon stevenvachon changed the title can.batch.start/stop causes can.List to render additional elements can.batch.start/stop causes can.List with length>1 to render last element twice Oct 9, 2014
@justinbmeyer
Copy link
Contributor

@stevenvachon great catch. @cklanac , this is maybe because two add events are fired and #each's add and remove handlers (https://github.com/bitovi/canjs/blob/master/view/live/live.js#L159) are not checking the batchNum.

You can see how https://github.com/bitovi/canjs/blob/master/compute/compute.js#L233 checks the batch num.

... however on second thought, that doesn't seem like the likely problem. Maybe the arguments are not right for the add event.

@justinbmeyer justinbmeyer added this to the 2.2.0 milestone Feb 11, 2015
cklanac added a commit that referenced this issue Feb 19, 2015
Add a batchNum property to can.batch. Add check in can.live.list add method to determine if current event was triggered during a batch job. if so, then exit the add. Fixes #680.
cklanac added a commit that referenced this issue Feb 19, 2015
Add a batchNum property to can.batch. Add check in can.live.list add method to determine if current event was triggered during a batch job. if so, then exit the add. Fixes #680.
@cklanac
Copy link
Contributor

cklanac commented Feb 20, 2015

@stevenvachon Thanks for submitting the issues. This issue is caused by the {{#if breaks.length}} helper interacting with the batched update and {{#each breaks}} helper. We've a fix to the next release.

In the meantime, you can workaround the issue by removing the .length from the if helper - simply {{#if breaks}}... {{/if}}, or change {{#each breaks}} helper to simply {{#breaks}}{{.}}{{/breaks}}.

http://canjs.com/docs/can.stache.Sections.html#section_Iteration

http://jsfiddle.net/cklanac/wfm6k20r/

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

Successfully merging a pull request may close this issue.

5 participants