repeat.for renders same item twice
I have a strange issue where when I try to push an empty object to an array that is rendered in my view - the newly pushed element is rendered twice.
The duplicate element is in fact the exact same element as the previous one (if I change the first the second also changes).
I'm unable to reproduce this in a GistRun (perhaps version differences) - but I have managed to reproduce it in a completely new Aurelia CLI project with the following code:
app.js
export class App {
constructor () {
this.items = [];
this.editing = false;
}
// Toggle the edit form
toggleEditing () {
this.editing = !this.editing;
// Also add a new item
if (this.editing) {
this.items.push({}); // NOTE: This is where things go wrong
}
}
}
And this view:
app.html
<template>
<template if.bind="!editing">
<h2>${items.length} items!</h2>
<ul>
<li repeat.for="item of items">
${item.name}
</li>
</ul>
<button click.delegate="toggleEditing()">Edit</button>
</template>
<template if.bind="editing">
<ul>
<li repeat.for="item of items">
<input type="text" value.bind="item.name">
</li>
</ul>
<button click.delegate="toggleEditing()">Save</button>
</template>
</template>
My package.json looks like this (for version info):
package.json
{
"name": "autest",
"description": "An Aurelia client application.",
"version": "0.1.0",
"repository": {
"type": "???",
"url": "???"
},
"license": "MIT",
"dependencies": {
"aurelia-bootstrapper": "^2.1.1",
"aurelia-animator-css": "^1.0.2",
"bluebird": "^3.4.1",
"requirejs": "^2.3.2",
"text": "github:requirejs/text#latest"
},
"peerDependencies": {},
"devDependencies": {
"aurelia-cli": "^0.31.3",
"aurelia-testing": "^1.0.0-beta.3.0.1",
"aurelia-tools": "^1.0.0",
"gulp": "github:gulpjs/gulp#4.0",
"minimatch": "^3.0.2",
"through2": "^2.0.1",
"uglify-js": "^3.0.19",
"vinyl-fs": "^2.4.3",
"babel-eslint": "^6.0.4",
"babel-plugin-syntax-flow": "^6.8.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-es2015-modules-amd": "^6.8.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.10.3",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-1": "^6.5.0",
"babel-polyfill": "^6.9.1",
"babel-register": "^6.24.0",
"gulp-babel": "^6.1.2",
"gulp-eslint": "^2.0.0",
"gulp-htmlmin": "^3.0.0",
"html-minifier": "^3.2.3",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-babel-preprocessor": "^6.0.1",
"browser-sync": "^2.13.0",
"connect-history-api-fallback": "^1.2.0",
"debounce": "^1.0.2",
"gulp-changed-in-place": "^2.0.3",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-notify": "^2.2.0",
"gulp-watch": "^4.3.11"
}
}
Maybe it's something obvious I've missed? But it seems like a genuine bug to me.
I'm attaching my example app as well which exhibits the bug and can be run in Firefox directly. Just click "Edit" and two input fields will be shown instead of one - changing one actually changes both.
If you are using [email protected], possibly it's related to aurelia/templating-resources#317
@bigopon I am indeed using 1.5.1. I'm not sure they're related though?
I've simplified my example code slightly. And FYI I'm using Aurelia CLI 0.31.3 (which I believe is the latest version?)
Do you get the same issue if you remove the if-part from the example?
@jwx I do not. Removing the if solves the issue. Also switching to show instead of if solves it - however, show does not appear to work with <template>.
Edit: I guess it might be the exact same issue then?
@powerbuoy Then the problem is probably with if, so yeah, at least related to it. There's a fix in that one that you could try and see if it helps.
Ok, honestly I'm not sure how I would implement the fix? You mean the ifCore override right?
I went ahead and updated all Aurelia packages today (I basically deleted node_modules and just reinstalled everything with my package.json pointing to the latest versions of all packages). I've also got the latest version of node and npm.
However, I still get the same issue as above and now new issues are introduced that also seem related to if.bind. When toggling the visibility of a <template> things (bindings) simply stop working. My app is littered with this code so it isn't really feasible for me to change it all now.
I'm guessing this is the same issue as mentioned in https://github.com/aurelia/templating-resources/issues/317 and https://github.com/aurelia/templating-resources/issues/315
How does one go about rolling back to a previous version? Most of the Aurelia packages aren't in package.json so not sure how their version numbers are controlled?
How does one go about rolling back to a previous version? Most of the Aurelia packages aren't in package.json so not sure how their version numbers are controlled?
I've spent hours trying to rollback to a previous version with JSPM. Without luck. Problem was, that I'm not able to LOCK a specific version of templating-resources and it's gonna overridden by the dependency tree: aurelia-materialize-bridge -> aurelia-framework -> aurelia-templating -> aurelia-templating-resources.
If you figured out how to rollback, tell me, I will really appreciate that!
I've pretty much swapped out all my if.bind:s to show.bind:s instead and while it meant I had to re-code some stuff that will require rigorous testing it seems to be working at first glance for now at least.
Here's hoping for an official patch soon :)
I've pretty much swapped out all my if.bind:s to show.bind:s instead and while it meant I had to re-code some stuff that will require rigorous testing it seems to be working at first glance for now at least.
Yes, but that doesn't help for repeat.
I see there's a fix for both https://github.com/aurelia/templating-resources/issues/317 and https://github.com/aurelia/templating-resources/issues/315 out. However, my repeat.for issue, as well as the issues I have with if.bind are not solved by the new release.
I managed to reproduce my issue in gist.run now as well; https://gist.run/?id=af8b192abd4ce89a62fe1383dba79d93
Changing from if.bind to show.bind solves it there too. I'm not 100% sure that gist is using the latest version of everything, but this same thing happens locally with everything updated ([email protected])
@powerbuoy Not released yet.
Ah ok, my bad :) I guess the fix is in templating-resources?
Yes.
This is happening to me, but has nothing to do with if or show:
The result is that the content is rendered twice for each array item that is added using myArray.push(newItem) after the view has been bound.
What is really weird is that when I do a production build, the bug goes away.
<template>
<div repeat.for='item of myArray'>
Item
</div>
</template>
I am on aurelia-templating-resources v1.5.3
OK, referring to my repro case just above ^^^, I figured out how to make the bug go away, even in my dev build. First, note that this applies to aurelia-typescript-webpack. The change is in webpack.config.js.
The original, that works, looks like this in the entry property:
entry: {
app: ['aurelia-bootstrapper'],
vendor: ['bluebird', 'jquery', 'bootstrap'],
}
What doesn't work, and causes this bug to happen in the development build, is the following:
entry: {
app: ['aurelia-bootstrapper'],
vendor: [
'bluebird',
'aurelia-templating',
'aurelia-binding',
'aurelia-router',
'aurelia-templating-binding',
'aurelia-polyfills',
'aurelia-event-aggregator',
'bootstrap',
'jquery',
],
}
I'm still seeing this issue in my app, using [email protected]. This bug is causing me to have to jump through all kinds of hoops to avoid.
@esmoore68 does it occur with [email protected] ?
@jods4 If it's ok with 1.4.0, then i think repeat has some issue, not the if
I just tried a CLI build with no problems - [email protected].
@esmoore68 please provide a repro of the problem you are facing.
@StrahilKazlachev You might be able to repro with a webpack.config such as I described above.
@StrahilKazlachev, the actual cases (there are many) in my app might be difficult to distill, but I can easily recreate using the test case created by @powerbuoy above.
@bigopon- It still happens with [email protected].
Aurelia entries from my packages.json:
"aurelia-animator-css": "^1.0.1",
"aurelia-binding": "^1.5.0",
"aurelia-bootstrapper": "^2.1.1",
"aurelia-dialog": "^1.0.0-rc.1.0.3",
"aurelia-event-aggregator": "^1.0.1",
"aurelia-fetch-client": "^1.1.1",
"aurelia-http-client": "^1.0.4",
"aurelia-templating": "^1.6.0",
"aurelia-templating-resources": "^1.4.0",
"aurelia-validation": "^1.0.0",
I am using Typescript and Webpack.
related settings from my webpack.config:
const {AureliaPlugin, ModuleDependenciesPlugin } = require("aurelia-webpack-plugin");
module.exports = {
entry: "aurelia-bootstrapper",
},