diff --git a/mithril.js b/mithril.js index b5b29143..bba36074 100644 --- a/mithril.js +++ b/mithril.js @@ -134,6 +134,7 @@ var m = (function app(window, undefined) { } } if (shouldMaintainIdentities) { + if (data.indexOf(null) > -1) data = data.filter(function(x) {return x != null}) for (var i = 0; i < data.length; i++) { if (data[i] && data[i].attrs) { if (data[i].attrs.key != null) { diff --git a/tests/index.html b/tests/index.html index 340feec3..9929de81 100644 --- a/tests/index.html +++ b/tests/index.html @@ -1,5 +1,5 @@ - + diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 4160d24b..080cb352 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -780,6 +780,14 @@ function testMithril(mock) { m.render(root, {foo: 123}) return root.childNodes.length == 0 }) + test(function() { + //https://github.com/lhorie/mithril.js/issues/299 + var root = mock.document.createElement("div") + m.render(root, m("div", [m("div", {key: 1}, 1), m("div", {key: 2}, 2), m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key: 5}, 5), null, null, null, null, null, null, null, null, null, null])) + m.render(root, m("div", [null, null, m("div", {key: 3}, 3), null, null, m("div", {key: 6}, 6), null, null, m("div", {key: 9}, 9), null, null, m("div", {key: 12}, 12), null, null, m("div", {key: 15}, 15)])) + m.render(root, m("div", [m("div", {key: 1}, 1), m("div", {key: 2}, 2), m("div", {key: 3}, 3), m("div", {key: 4}, 4), m("div", {key: 5}, 5), null, null, null, null, null, null, null, null, null, null])) + return root.childNodes[0].childNodes.map(function(c) {return c.childNodes ? c.childNodes[0].nodeValue: c.nodeValue}).slice(0, 5).join("") == "12345" + }) //end m.render //m.redraw