diff --git a/mithril.js b/mithril.js index 39898615..f0cd1ca2 100644 --- a/mithril.js +++ b/mithril.js @@ -241,7 +241,7 @@ var m = (function app(window, undefined) { var controllerIndex = cached.controllerConstructors ? cached.controllerConstructors.indexOf(controllerConstructor) : -1 var controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || function() {}) var key = data && data.attrs && data.attrs.key - data = pendingRequests == 0 ? data.view(controller) : {tag: "placeholder"} + data = pendingRequests == 0 || cached ? data.view(controller) : {tag: "placeholder"} if (key) { if (!data.attrs) data.attrs = {} data.attrs.key = key diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index f22dd069..d1fa84ab 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -960,6 +960,79 @@ function testMithril(mock) { return root.childNodes[0].nodeName == "DIV" }) + test(function() { + //https://github.com/lhorie/mithril.js/issues/551 + var root = mock.document.createElement("div") + var a = false, found = false, unloaded = false + var Root = { + view: function() { + return Comp + } + } + var Comp = { + view: function() { + return m("div", {config: Comp.config}, [ + m("div", {onclick: function() { + a = !a + m.redraw(true) + found = root.childNodes[0].childNodes[1] + }}, "asd"), + a ? m("#a", "aaa") : null, + "test" + ]) + }, + config: function(el, init, ctx) { + if (!init) ctx.onunload = function() { + unloaded = true + } + } + } + m.mount(root, Root) + + var target = root.childNodes[0].childNodes[0] + target.onclick({currentTarget: target}) + + mock.requestAnimationFrame.$resolve() + + return !unloaded && found.id === "a" + }) + test(function() { + //https://github.com/lhorie/mithril.js/issues/551 + var root = mock.document.createElement("div") + var a = false, found = false, unloaded = false + var Root = { + view: function() { + return Comp + } + } + var Comp = { + view: function() { + return m("div", {config: Comp.config}, [ + m("div", {onclick: function() { + a = !a + m.redraw(true) + found = root.childNodes[0].childNodes[1] + m.redraw.strategy("none") + }}, "asd"), + a ? m("#a", "aaa") : null, + "test" + ]) + }, + config: function(el, init, ctx) { + if (!init) ctx.onunload = function() { + unloaded = true + } + } + } + m.mount(root, Root) + + var target = root.childNodes[0].childNodes[0] + target.onclick({currentTarget: target}) + + mock.requestAnimationFrame.$resolve() + + return !unloaded && found.id === "a" + }) m.redraw.strategy(undefined) //teardown for m.mount tests //m.withAttr