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

Comments

Projects
None yet
5 participants
@stevenvachon
Contributor

stevenvachon commented Jan 19, 2014

{{#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

This comment has been minimized.

Show comment
Hide comment
@stevenvachon

stevenvachon Oct 9, 2014

Contributor

Updated fiddle with can.stache. The issue persists.

Contributor

stevenvachon commented Oct 9, 2014

Updated fiddle with can.stache. The issue persists.

@gsmeets

This comment has been minimized.

Show comment
Hide comment
@gsmeets

gsmeets Oct 9, 2014

Contributor

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

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 from can.batch.start/stop causes can.List to render additional elements to can.batch.start/stop causes can.List with length>1 to render last element twice Oct 9, 2014

@justinbmeyer justinbmeyer added the bug label Feb 11, 2015

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Feb 11, 2015

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.

Contributor

justinbmeyer commented Feb 11, 2015

@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 check in live.list to determine if current event is part of a batch.
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 check in live.list to determine if current event is part of a batch.
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 cklanac closed this in #1458 Feb 19, 2015

@cklanac

This comment has been minimized.

Show comment
Hide comment
@cklanac

cklanac Feb 20, 2015

Contributor

@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/

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